1. 程式人生 > 其它 >03.maven連線nexus私服配置以及maven settings.xml檔案詳解

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