【Maven】Nexus配置和使用


Nexus安裝

  nexus安裝,可以參照:【Maven】Nexus(Maven倉庫私服)下載與安裝

Nexus簡單說明

  •  用途:指定私服的中央地址、將自己的Maven項目指定到私服地址、從私服下載中央庫的項目索引、從私服倉庫下載依賴組件、將第三方項目jar上傳到私服供其他項目組使用
  •    倉庫:

      hosted   類型的倉庫,內部項目的發布倉庫 

      releases 內部的模塊中release模塊的發布倉庫

      snapshots 發布內部的SNAPSHOT模塊的倉庫  

      3rd party 第三方依賴的倉庫,這個數據通常是由內部人員自行下載之后發布上去 

      proxy   類型的倉庫,從遠程中央倉庫中尋找數據的倉庫

      group   類型的倉庫,組倉庫用來方便我們開發人員進行設置的倉庫

      

Nexus配置

  nexus配置大部分使用默認配置即可,主要是配置一個項目索引

  選擇Central倉庫,設置Download Remote Indexes:True

  

Nexus使用

  •   項目使用nexus私服的jar包,在項目的pom.xml文件中指定私服倉庫
     1 <repositories>
     2     <repository>
     3         <id>nexus</id>
     4         <name>nexus</name>
     5         <url>http://192.168.1.103:8081/nexus/content/groups/public/</url>
     6         <releases>
     7             <enabled>true</enabled>
     8         </releases>
     9         <snapshots>
    10             <enabled>true</enabled>
    11         </snapshots>
    12     </repository>
    13 </repositories>

     

  •   項目使用nexus私服的插件,在項目的pom.xml文件中指定插件倉庫
     1 <pluginRepositories>
     2     <pluginRepository>
     3         <id>nexus</id>
     4         <name>nexus</name>
     5         <url>http://192.168.1.103:8081/nexus/content/groups/public/</url>
     6         <releases>
     7             <enabled>true</enabled>
     8         </releases>
     9         <snapshots>
    10             <enabled>true</enabled>
    11         </snapshots>
    12     </pluginRepository>
    13 </pluginRepositories>

     

  •   如果想本機所有的maven項目都使用私服的組件,可以在maven的設置文件settings.xml中添加屬性,並激活
     1 <profiles>
     2     <profile>
     3         <id>nexusProfile</id>
     4         <repositories>
     5             <repository>
     6                 <id>nexus</id>
     7                 <name>nexus</name>
     8                 <url>http://192.168.1.103:8081/nexus/content/groups/public/</url>
     9                 <releases>
    10                     <enabled>true</enabled>
    11                 </releases>
    12                 <snapshots>
    13                     <enabled>true</enabled>
    14                 </snapshots>
    15             </repository>
    16         </repositories>
    17     </profile>
    18 </profiles>
    19 <!-- 激活 -->
    20 <activeProfiles>
    21     <activeProfile>nexusProfile</activeProfile>
    22 </activeProfiles>

     

  •  項目發布到私服,maven項目使用命令:mvn clean deploy;需要在pom文件中配置一下代碼;
     1 <distributionManagement>
     2         <repository>
     3             <id>user-release</id>
     4             <name>User Project Release</name>
     5             <url>http://192.168.1.103:8081/nexus/content/repositories/releases/</url>
     6         </repository>
     7 
     8         <snapshotRepository>
     9             <id>user-snapshots</id>
    10             <name>User Project SNAPSHOTS</name>
    11             <url>http://192.168.1.103:8081/nexus/content/repositories/snapshots/</url>
    12         </snapshotRepository>
    13     </distributionManagement>

    注意還需要配置mvn發布的權限,否則會報401錯誤,在settings.xml中配置權限,其中id要與pom文件中的id一致

     1 <server>
     2     <id>user-release</id>
     3     <username>admin</username>
     4     <password>admin123</password>
     5 </server>
     6 <server>
     7     <id>user-snapshots</id>
     8     <username>admin</username>
     9     <password>admin123</password>
    10 </server>

    發布成功后,可以在nexus中看到

    

  •   上傳第三方的jar包,選擇3rd party-->Artifact Upload--> 選擇GAV方式-->填好構建參數-->增加jar包-->上傳,在Browse Storeage查看

   

   

 


免責聲明!

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



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