`
cantellow
  • 浏览: 843010 次
  • 性别: Icon_minigender_1
  • 来自: 草帽海贼团
社区版块
存档分类
最新评论

使用Nexus管理maven仓库,setting文件理解

 
阅读更多

来到新公司对很多陌生的技术一头雾水,以前在工作中没有真正使用过maven,于是强迫自己蛋定下来一个一个的突破,下面是我对maven的setting配置文件的理解,由于是现学的,难免可能会理解偏差,还请牛人路过指正。

 

<!--
xuze added by:添加了一些注释,利于新人理解
Date:2011年7月18日
-->
<settings>
  <!-- 配置镜像 -->
  <mirrors>  	
    <mirror>
	  <!-- 此镜像一般用来作为公司内部开发的版本快照,作为public-snapshots仓库的镜像地址 -->
	  <!-- 镜像的id,id用来区分不同的mirror元素。 --> 
      <id>nexus-public-snapshots</id>
	  <!-- 被镜像的服务器的id。例如,如果我们要设置了一个Maven中央仓库(http://repo1.maven.org/maven2)的镜像,
	  	就需要将该元素设置成central。这必须和中央仓库的id “central”完全一致。 -->
      <mirrorOf>public-snapshots</mirrorOf>
	  <!-- 该镜像的URL。 --> 
      <url>http://repos.d.xxx.com/nexus/content/groups/public-snapshots</url>
    </mirror>
	
    <mirror>
	  <!-- 此镜像一般用来作为公司第三方引用基础类库镜像,是所有仓库的镜像地址 -->
      <id>nexus</id>
	  <!-- 为*表示为所有的仓库做镜像,有了这个配置,所有的构建都会包含public组,如果你想包含public-snapshots组,
	  	你必须添加public-snapshots这个Profile,通过在命令行使用如下的 -P 标志:$ mvn -P public-snapshots clean install -->
      <mirrorOf>*</mirrorOf>
      <url>http://repos.d.xxx.com/nexus/content/groups/public</url>
    </mirror>	
  </mirrors>
  
  <!-- settings.xml中的profile元素是pom.xml中profile元素的裁剪版本。它包含了activation, repositories, pluginRepositories 和 properties元素。
  	这里的profile元素只包含这四个子元素是因为这里只关心构建系统这个整体(这正是settings.xml文件的角色定位),而非单独的项目对象模型设置。  
	如果一个settings中的profile被激活,它的值会覆盖任何其它定义在POM中或者profile.xml中的带有相同id的profile。 --> 
  <profiles>
    <profile>
      <id>development</id>
	  <!-- 仓库。仓库是Maven用来填充构建系统本地仓库所使用的一组远程项目。而Maven是从本地仓库中使用其插件和依赖。
	  	不同的远程仓库可能含有不同的项目,而在某个激活的profile下,可能定义了一些仓库来搜索需要的发布版或快照版构件。有了Nexus,这些应该交由Nexus完成 -->
      <repositories>
        <repository>
          <id>central</id>
		  <!-- 虚拟的URL形式,指向镜像的URL,因为所有的镜像都是用的是nexus,这里的central实际上指向的是http://repos.d.xxx.com/nexus/content/groups/public -->
          <url>http://central</url>
		  <!-- 表示可以从这个仓库下载releases版本的构件-->
          <releases><enabled>true</enabled></releases>
		  <!-- 表示可以从这个仓库下载snapshot版本的构件 -->
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
	 
	 <!-- 插件仓库。仓库是两种主要构件的家。第一种构件被用作其它构件的依赖。这是中央仓库中存储大部分构件类型。
	 	另外一种构件类型是插件。Maven插件是一种特殊类型的构件。由于这个原因,插件仓库独立于其它仓库。
		pluginRepositories元素的结构和repositories元素的结构类似。每个pluginRepository元素指定一个Maven可以用来寻找新插件的远程地址。 -->  
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
	
    <profile>
      <!--this profile will allow snapshots to be searched when activated-->
      <id>public-snapshots</id>
      <repositories>
        <repository>
          <id>public-snapshots</id>
		  <!-- 虚拟的URL形式,指向镜像的URL,这里指向的是http://repos.d.xxx.com/nexus/content/groups/public-snapshots -->
          <url>http://public-snapshots</url>
          <releases><enabled>false</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>public-snapshots</id>
          <url>http://public-snapshots</url>
          <releases><enabled>false</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  
  <!-- 激活的Profile。activation元素并不是激活profile的唯一方式。settings.xml文件中的activeProfile元素可以包含profile的id,
  	任何在activeProfile中定义的profile id,不论环境设置如何,其对应的profile都会被激活。如果没有匹配的profile,则什么都不会发生。
	profile也可以通过在命令行,使用-P标记和逗号分隔的列表来显式的激活(如,-P test)。
	要了解在某个特定的构建中哪些profile会激活,可以使用maven-help-plugin(mvn help:active-profiles)。 -->  
  <activeProfiles>
  	<!-- 没有显示激活public-snapshots -->
    <activeProfile>development</activeProfile>
  </activeProfiles>

<!-- 自定义本地仓库地址,其默认值为~/.m2/repository -->
<localRepository>/data/maven-repository</localRepository>

  <!-- 发布的服务器和密码,暂时未限制权限 -->
   <servers>
    <server>
      <!-- 发布的位置在POM中配置,以ID为关联,有很多公用的信息需要配置在POM文件里,最佳实践是定义一个公司级别的root pom -->
      <id>archiva.internal</id>
      <username>maven</username>
      <password>1q2w3e4r</password>
    </server>
    <server>
      <id>archiva.snapshots</id>
      <username>maven</username>
      <password>1q2w3e4r</password>
    </server>
  </servers>
</settings>
2
2
分享到:
评论
3 楼 rlplyyrb 2011-09-22  
在项目的配置文件pom.xml里配置如下代码:
<distributionManagement>
<repository>
<id>releases</id>
<name>Internal Releases</name>
<url>http://localhost:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>Snapshots</id>
<name>Internal Snapshots</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

那么在你使用mvn deploy发布项目时,如果是release版本的话,会将项目自动部署到nexus的宿主仓库releases里,如果是开发版本的话,会将项目自动部署到nexus的宿主仓库snapshots里。这里区分是release版本还是snapshots版本的关键在于:你的POM文件的版本号有没有-SNAPSHOT。比如:<version> 1.0 </version>这个为release版本,<version>1.0-SNAPSHOT</version>这个为snapshots版本。
2 楼 cantellow 2011-07-19  
snake1987 写道
这应该是maven的setting文件的东西吧,很多东西貌似还需要nexus配置,像自动下载源代码,deploy自动上传源代码,snapshot的管理等等,坐等你研究出来,呵呵

估计最近是没有时间再对maven深一步了,因为还有很多其他的东西等着我去了解,深入的话,应该是第二轮学习吧。
1 楼 snake1987 2011-07-19  
这应该是maven的setting文件的东西吧,很多东西貌似还需要nexus配置,像自动下载源代码,deploy自动上传源代码,snapshot的管理等等,坐等你研究出来,呵呵

相关推荐

    官网下载的professional版:nexus-professional-2.15.1-02-bundle

    Nexus是一套“开箱即用”的系统不需要数据库,它使用文件系统加Lucene来组织数据。 Nexus不是Maven的核心概念,它仅仅是一种衍生出来的特殊的Maven仓库。对于Maven来说,仓库只有两种:本地仓库和远程仓库。 本地...

    maven私服(nexus)配置(setting,pom.xml)

    maven配置使用本地搭建的nexus作为本地中央仓库时候,依赖的下载和发布设置涉及到的配置文件:setting,pom.xml

    使用Maven&nexus上传下载至私库

    2、 配置maven conf/setting.xml文件 添加上传验证 &lt;id&gt;release &lt;username&gt;admin &lt;password&gt;admin123 &lt;id&gt;snapshot &lt;username&gt;admin &lt;password&gt;admin123 添加私库镜像,用于代理中央仓库,提供下载

    maven window下安装包

    第6章:仓库/6.1 何为Maven仓库 第6章:仓库/6.2 仓库的布局 第6章:仓库/6.3 仓库的分类 第6章:仓库/6.3 仓库的分类/6.3.1 本地仓库 第6章:仓库/6.3 仓库的分类/6.3.1 本地仓库/6.3.1.1 setting.xml文件路径 第6...

    关于MAVEN仓库服务器的安装与一些maven相关配置

    文档总结了搭建maven私服管理器nexus时遇到的一些问题,建议各位使用nexus2.*版本; 文档描述了pom以及setting的一些配置

    Maven权威指南 很精典的学习教程,比ANT更好用

    Maven仓库(Repositories) 3.5.5. Maven依赖管理 (Dependency Management) 3.5.6. 站点生成和报告 (Site Generation and Reporting) 3.6. 小结 4. 定制一个Maven项目 4.1. 介绍 4.1.1. 下载本章样例 4.2...

    解决IDEA中maven添加dependency过慢的问题

    我们在IDEA的安装目录下找到 /plugins/maven/lib/maven2/conf 或者 /plugins/maven/lib/maven3/conf目录(如果两个都有建议都改掉),向其中的setting.xnl文件中的/标签下添加如下的仓库地址(这里以阿里云为例): ...

    maven的优缺点 项目

    千万不要将文档中的setting的内容全部替换到maven中的内容,要对比着修改,保留原来的; 只修改本地仓库,和下载镜像(源) 3.2.Eclipse Maven的配置 每打开一个新的工作空间,要配置一下Maven,然后再写代码 3.3.创建...

    nexus-3.19.0-01-win64.zip

    Nexus Repository Manager OSS是可以用来搭建一个远程仓库,可以搭建一个远程的maven私服,上传的时候可以使用以jar包的形式进行上传,会自动生成对应的xml依赖,只需要在本地的setting.xml当中加入该仓库作为远程地址就...

    settings.xml

    maven阿里云镜像配置xml &lt;id&gt;alimaven &lt;name&gt;aliyun maven &lt;url&gt;http://maven.aliyun.com/nexus/content/groups/public/&lt;/url&gt; &lt;mirrorOf&gt;central&lt;/mirrorOf&gt; 本地仓库记得配置

    test-jenkins.zip

    maven的setting配置,以及一个idea项目的pom.xml配置,可以直接将文件推送到nexus私服上去了,只需要将地址配置成自己的私服,在自己的nexus私服中创建对应的账号,创建对应的仓库。

    tdmq-spring-boot-starter-parent:腾讯TDMQ产品,SpringBoot启动器

    需要添加腾讯的maven仓库到setting.xml中 添加私服配置 找到Maven所使用的配置文件,一般在〜/ .m2 / settings.xml中,在settings.xml中加入如下配置: &lt;id&gt;nexus &lt;id&gt;central &lt;url&gt;...

Global site tag (gtag.js) - Google Analytics