03.maven連接nexus私服配置以及maven settings.xml文件詳解


settings.xml有什么用?

 

如果在Eclipse中使用過Maven插件,想必會有這個經驗:配置settings.xml文件的路徑。

 

settings.xml文件是干什么的,為什么要配置它呢?

從settings.xml的文件名就可以看出,它是用來設置maven參數的配置文件。並且,settings.xml是maven的全局配置文件。而pom.xml文件是所在項目的局部配置。

Settings.xml中包含類似本地倉儲位置、修改遠程倉儲服務器、認證信息等配置。

 

settings.xml文件位置

 

settings.xml文件一般存在於兩個位置:

全局配置: ${M2_HOME}/conf/settings.xml

用戶配置: {user.home} 和和所有其他系統屬性只能在3.0+版本上使用。請注意windows和Linux使用變量的區別。

 

配置優先級

 

需要注意的是:局部配置優先於全局配置。

配置優先級從高到低:pom.xml> user settings > global settings

如果這些文件同時存在,在應用配置時,會合並它們的內容,如果有重復的配置,優先級高的配置會覆蓋優先級低的。

 

maven怎么從遠程倉庫下載jar包,setting中配置:

     <!--  我們使用maven下載需要的jar包,但是很多的時候由於中央倉庫沒有,所以此處可以在maven的設置中心添加多個下載倉庫,當中央倉庫沒有的話,繼續到下一個倉庫去下載。這樣豐富了中央倉庫的下載地址。  -->

     <mirror>

      <id>nexus</id>

      <name>nexus maven</name>

      <url>http://localhost:8081/repository/maven-public/</url>

      <mirrorOf>*</mirrorOf>        

     </mirror> 

 

     <mirror>

      <id>alimaven</id>

      <name>aliyun maven</name>

      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>

      <mirrorOf>central</mirrorOf>        

     </mirror> 

 

     <mirror>  

      <id>repo2</id>  

      <mirrorOf>central</mirrorOf>  

      <name>Human Readable Name for this Mirror.</name>  

      <url>http://repo2.maven.org/maven2/</url>  

    </mirror>

  </mirrors>

 

Nexus配置
項目使用nexus私服的jar包,在項目的pom.xml文件中指定私服倉庫

<repositories>

      <repository>

          <id>nexus</id>

          <name>nexus</name>

          <url>http://192.168.1.103:8081/nexus/content/groups/public/</url>

          <releases>

              <enabled>true</enabled>

          </releases>

          <snapshots>

             <enabled>true</enabled>

         </snapshots>

     </repository>

 

 </repositories>

 

項目使用nexus私服的插件,在項目的pom.xml文件中指定插件倉庫

 <pluginRepositories>

      <pluginRepository>

          <id>nexus</id>

          <name>nexus</name>

          <url>http://192.168.1.103:8081/nexus/content/groups/public/</url>

          <releases>

              <enabled>true</enabled>

          </releases>

          <snapshots>

             <enabled>true</enabled>

         </snapshots>

     </pluginRepository>

 

 </pluginRepositories>

如果想本機所有的maven項目都使用私服的組件,可以在maven的設置文件settings.xml中添加屬性,並激活

  <profile>

       <id>Nexus</id>

       <repositories>

         <repository>

          <id>nexus</id>

          <url>http://localhost:8081/repository/maven-public/</url>

          <releases><enabled>true</enabled></releases>

          <snapshots><enabled>true</enabled></snapshots>

         </repository>

       </repositories>

       <pluginRepositories>

         <pluginRepository>

           <id>nexus</id>

           <url>http://localhost:8081/repository/maven-public/</url>

           <releases>

            <enabled>true</enabled>

           </releases>

          <snapshots>

            <enabled>true</enabled>

          </snapshots>

         </pluginRepository>

        </pluginRepositories>

     </profile>

  </profiles>

  <!-- 激活 -->

  <activeProfiles>

    <activeProfile>Nexus</activeProfile>

 

  </activeProfiles>

 

如何將自己的項目發布到nexus私服

 

我們知道用mvn install命令可以將項目裝載的本地的倉庫,但是項目發布到私服,maven項目就要使用命令:mvn clean deploy;

要想發布項目到nexus里,必須通過標簽來進行配置。在之前的文章中有介紹nexus的工廠類別,其中提到兩個:hosted里的Releases、Snapshots.

 

當我們發布項目到nexus里時,如果項目版本是x.x.x-Releases,則會發布到Releases工廠中;而項目版本是x.x.x-SNAPSHOTS則發布到Snapshots工廠中。

需要在pom文件中配置一下代碼;

<distributionManagement>

        <repository>

            <id>nexus-releases</id>

            <name>Nexus Release Repository</name>

            <url>http://localhost:8081/repository/maven-releases/</url>

        </repository>

        <snapshotRepository>

            <id>nexus-snapshots</id>

            <name>Nexus Snapshot Repository</name>

            <url>http://localhost:8081/repository/maven-snapshots//</url>

        </snapshotRepository>

 

    </distributionManagement>

 

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

  <!--授權信息  -->

      <server> 

        <id>nexus-releases</id> 

        <username>admin</username> 

        <password>admin123</password> 

      </server> 

      <server> 

        <id>nexus-snapshots</id> 

        <username>admin</username> 

        <password>admin123</password> 

      </server>

這里面的username和password對應的是nexus私服中具有發布權限的用戶名和密碼

 

原文地址:https://blog.csdn.net/u011217058/article/details/79418317

http://blog.csdn.net/u012225679/article/details/73740785

https://www.cnblogs.com/jingmoxukong/p/6050172.html?utm_source=gold_browser_extension

http://blog.csdn.net/moshenglv/article/details/52027125

http://blog.csdn.net/haohaizijhz/article/details/72841489

https://www.cnblogs.com/h–d/p/5719040.html

http://blog.csdn.net/cwh056056/article/details/49667971

 

下載

https://blog.csdn.net/weixin_43943548/article/details/107035485

 

使用

https://www.cnblogs.com/fly-book/p/15141282.html

https://www.cnblogs.com/fanjingfeng/p/14411817.html

 

https://blog.csdn.net/g631521612/article/details/107156944/?utm_term=mavenwindows%E7%A7%81%E6%9C%89%E4%BB%93%E5%BA%93&utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~all~sobaiduweb~default-1-107156944&spm=3001.4430

導入

https://www.cnblogs.com/anlalala/p/15608073.html

 


免責聲明!

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



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