使用Nexus管理maven倉庫,setting文件理解


來到新公司對很多陌生的技術一頭霧水,以前在工作中沒有真正使用過maven,於是強迫自己蛋定下來一個一個的突破,下面是我對maven的setting配置文件的理解,由於是現學的,難免可能會理解偏差,還請牛人路過指正。

 

Xml代碼   收藏代碼
  1. <!--  
  2. xuze added by:添加了一些注釋,利於新人理解  
  3. Date:2011年7月18日  
  4. -->  
  5. <settings>  
  6.   <!-- 配置鏡像 -->  
  7.   <mirrors>     
  8.     <mirror>  
  9.       <!-- 此鏡像一般用來作為公司內部開發的版本快照,作為public-snapshots倉庫的鏡像地址 -->  
  10.       <!-- 鏡像的id,id用來區分不同的mirror元素。 -->   
  11.       <id>nexus-public-snapshots</id>  
  12.       <!-- 被鏡像的服務器的id。例如,如果我們要設置了一個Maven中央倉庫(http://repo1.maven.org/maven2)的鏡像,  
  13.         就需要將該元素設置成central。這必須和中央倉庫的id “central”完全一致。 -->  
  14.       <mirrorOf>public-snapshots</mirrorOf>  
  15.       <!-- 該鏡像的URL。 -->   
  16.       <url>http://repos.d.xxx.com/nexus/content/groups/public-snapshots</url>  
  17.     </mirror>  
  18.       
  19.     <mirror>  
  20.       <!-- 此鏡像一般用來作為公司第三方引用基礎類庫鏡像,是所有倉庫的鏡像地址 -->  
  21.       <id>nexus</id>  
  22.       <!-- 為*表示為所有的倉庫做鏡像,有了這個配置,所有的構建都會包含public組,如果你想包含public-snapshots組,  
  23.         你必須添加public-snapshots這個Profile,通過在命令行使用如下的 -P 標志:$ mvn -P public-snapshots clean install -->  
  24.       <mirrorOf>*</mirrorOf>  
  25.       <url>http://repos.d.xxx.com/nexus/content/groups/public</url>  
  26.     </mirror>   
  27.   </mirrors>  
  28.     
  29.   <!-- settings.xml中的profile元素是pom.xml中profile元素的裁剪版本。它包含了activation, repositories, pluginRepositories 和 properties元素。  
  30.     這里的profile元素只包含這四個子元素是因為這里只關心構建系統這個整體(這正是settings.xml文件的角色定位),而非單獨的項目對象模型設置。    
  31.     如果一個settings中的profile被激活,它的值會覆蓋任何其它定義在POM中或者profile.xml中的帶有相同id的profile。 -->   
  32.   <profiles>  
  33.     <profile>  
  34.       <id>development</id>  
  35.       <!-- 倉庫。倉庫是Maven用來填充構建系統本地倉庫所使用的一組遠程項目。而Maven是從本地倉庫中使用其插件和依賴。  
  36.         不同的遠程倉庫可能含有不同的項目,而在某個激活的profile下,可能定義了一些倉庫來搜索需要的發布版或快照版構件。有了Nexus,這些應該交由Nexus完成 -->  
  37.       <repositories>  
  38.         <repository>  
  39.           <id>central</id>  
  40.           <!-- 虛擬的URL形式,指向鏡像的URL,因為所有的鏡像都是用的是nexus,這里的central實際上指向的是http://repos.d.xxx.com/nexus/content/groups/public -->  
  41.           <url>http://central</url>  
  42.           <!-- 表示可以從這個倉庫下載releases版本的構件-->  
  43.           <releases><enabled>true</enabled></releases>  
  44.           <!-- 表示可以從這個倉庫下載snapshot版本的構件 -->  
  45.           <snapshots><enabled>true</enabled></snapshots>  
  46.         </repository>  
  47.       </repositories>  
  48.        
  49.      <!-- 插件倉庫。倉庫是兩種主要構件的家。第一種構件被用作其它構件的依賴。這是中央倉庫中存儲大部分構件類型。  
  50.         另外一種構件類型是插件。Maven插件是一種特殊類型的構件。由於這個原因,插件倉庫獨立於其它倉庫。  
  51.         pluginRepositories元素的結構和repositories元素的結構類似。每個pluginRepository元素指定一個Maven可以用來尋找新插件的遠程地址。 -->    
  52.      <pluginRepositories>  
  53.         <pluginRepository>  
  54.           <id>central</id>  
  55.           <url>http://central</url>  
  56.           <releases><enabled>true</enabled></releases>  
  57.           <snapshots><enabled>true</enabled></snapshots>  
  58.         </pluginRepository>  
  59.       </pluginRepositories>  
  60.     </profile>  
  61.       
  62.     <profile>  
  63.       <!--this profile will allow snapshots to be searched when activated-->  
  64.       <id>public-snapshots</id>  
  65.       <repositories>  
  66.         <repository>  
  67.           <id>public-snapshots</id>  
  68.           <!-- 虛擬的URL形式,指向鏡像的URL,這里指向的是http://repos.d.xxx.com/nexus/content/groups/public-snapshots -->  
  69.           <url>http://public-snapshots</url>  
  70.           <releases><enabled>false</enabled></releases>  
  71.           <snapshots><enabled>true</enabled></snapshots>  
  72.         </repository>  
  73.       </repositories>  
  74.      <pluginRepositories>  
  75.         <pluginRepository>  
  76.           <id>public-snapshots</id>  
  77.           <url>http://public-snapshots</url>  
  78.           <releases><enabled>false</enabled></releases>  
  79.           <snapshots><enabled>true</enabled></snapshots>  
  80.         </pluginRepository>  
  81.       </pluginRepositories>  
  82.     </profile>  
  83.   </profiles>  
  84.     
  85.   <!-- 激活的Profile。activation元素並不是激活profile的唯一方式。settings.xml文件中的activeProfile元素可以包含profile的id,  
  86.     任何在activeProfile中定義的profile id,不論環境設置如何,其對應的profile都會被激活。如果沒有匹配的profile,則什么都不會發生。  
  87.     profile也可以通過在命令行,使用-P標記和逗號分隔的列表來顯式的激活(如,-P test)。  
  88.     要了解在某個特定的構建中哪些profile會激活,可以使用maven-help-plugin(mvn help:active-profiles)。 -->    
  89.   <activeProfiles>  
  90.     <!-- 沒有顯示激活public-snapshots -->  
  91.     <activeProfile>development</activeProfile>  
  92.   </activeProfiles>  
  93.   
  94. <!-- 自定義本地倉庫地址,其默認值為~/.m2/repository -->  
  95. <localRepository>/data/maven-repository</localRepository>  
  96.   
  97.   <!-- 發布的服務器和密碼,暫時未限制權限 -->  
  98.    <servers>  
  99.     <server>  
  100.       <!-- 發布的位置在POM中配置,以ID為關聯,有很多公用的信息需要配置在POM文件里,最佳實踐是定義一個公司級別的root pom -->  
  101.       <id>archiva.internal</id>  
  102.       <username>maven</username>  
  103.       <password>1q2w3e4r</password>  
  104.     </server>  
  105.     <server>  
  106.       <id>archiva.snapshots</id>  
  107.       <username>maven</username>  
  108.       <password>1q2w3e4r</password>  
  109.     </server>  
  110.   </servers>  
  111. </settings>  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM