從Maven私服獲取依賴


通過Internet直接從Maven公用倉庫獲取依賴包是默認配置。不過對於中國軟件公司來講,訪問這些公用倉庫通常較慢,對於一些管理嚴格的不能直接上網的軟件公司來講,這更加是不可能的。Maven項目可以配置成僅從Maven私服上獲取依賴。

上一篇已經講述了如何安裝Nexus為Maven私服。下面就假定使用S1服務器上的Nexus服務。可以參考官方文檔:

http://www.sonatype.com/books/nexus-book/reference/config-sect-intro.html

在開發機器上有Maven項目,首先編輯~/.m2/settings.xml.

 

  1. <settings> 
  2.   <mirrors> 
  3.     <mirror> 
  4.       <!--This sends everything else to /public --> 
  5.       <id>nexus</id> 
  6.       <mirrorOf>*</mirrorOf> 
  7.       <url>http://S1:8081/nexus/content/groups/public</url> 
  8.     </mirror> 
  9.   </mirrors> 
  10.   <profiles> 
  11.     <profile> 
  12.       <id>nexus</id> 
  13.       <!--Enable snapshots for the built in central repo to direct --> 
  14.       <!--all requests to nexus via the mirror --> 
  15.       <repositories> 
  16.         <repository> 
  17.           <id>central</id> 
  18.           <url>http://central</url> 
  19.           <releases><enabled>true</enabled></releases> 
  20.           <snapshots><enabled>true</enabled></snapshots> 
  21.         </repository> 
  22.       </repositories> 
  23.       <pluginRepositories> 
  24.         <pluginRepository> 
  25.           <id>central</id> 
  26.           <url>http://central</url> 
  27.           <releases><enabled>true</enabled></releases> 
  28.           <snapshots><enabled>true</enabled></snapshots> 
  29.         </pluginRepository> 
  30.       </pluginRepositories> 
  31.     </profile> 
  32.   </profiles> 
  33.   <activeProfiles> 
  34.     <!--make the profile active all the time --> 
  35.     <activeProfile>nexus</activeProfile> 
  36.   </activeProfiles> 
  37. </settings> 

只需要把S1改成自己的Nexus服務器地址就可以了。如果你的Maven項目的pom.xml中沒有自定義的repository,那么就可以使用了。比如執行mvn clean compile命令,就可從S1上下載pom.xml和jar包。

 

<profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>http://172.27.2.203:8081/nexus/content/groups/public/</url>
        <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
        </repository>
      </repositories>
      
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://172.27.2.203:8081/nexus/content/groups/public/</url>
          <releases><enabled>true</enabled></releases>
           <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>

 

注意,有時候nexus上已經部署了最新的snapshot,但是mvn clean compile就是不取最新版本,這時候需要用-U 參數強制檢查。

mvn clean compile -U

如果還不行,則刪除本地緩存的目錄,在jenkins項目中可以在build之前執行一行命令,比如:

 

  1. rm -rf /usr/share/tomcat7/.m2/repository/com/esri/carrier/nginx-factory/ 


免責聲明!

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



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