來到新公司對很多陌生的技術一頭霧水,以前在工作中沒有真正使用過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>