配置Maven使用Nexus
有兩種方式
第一種:最簡單明了的方式
直接在你項目的pom.xml中添加如下
? ? <repositories> ? ? ? ? ? <repository> ? ? ? ? ? ? ? <snapshots> ? ? ? ? ? ? ? ? ? <enabled>true</enabled> ? ? ? ? ? ? ? </snapshots> ? ? ? ? ? ? ? <id>public</id> ? ? ? ? ? ? ? <name>Public Repositories</name> ? ? ? ? ? ? ? <url>http://localhost:8081/nexus/content/groups/public/</url> ? ? ? ? ? </repository> ? ? ? </repositories> ? ? ? <pluginRepositories> ? ? ? ? ? <pluginRepository> ? ? ? ? ? ? ? <id>public</id> ? ? ? ? ? ? ? <name>Public Repositories</name> ? ? ? ? ? ? ? <url>http://localhost:8081/nexus/content/groups/public/</url> ? ? ? ? ? </pluginRepository> ? ? ? </pluginRepositories> |
那么,maven會首先從你配置的公共倉庫中取信息,取不到再去默認的倉庫取
?
?
第二種: 配置稍復雜 ? ?
?
為了使用Nexus,你將要配置Maven去檢查Nexus而不是公共倉庫。為此,你需要需該Maven的mirror setting,該配置文件在~/.m2/settings.xml也有可能是Maven目下路conf/settings.xml.首先,我們演示如何配置Maven查閱你的Nexus而不是Maven Central repository。然后我們重寫central repository并驗證Nexus是工作的。
? ??配置Maven使用單個Nexus Group
? ? 如果你想更改Nexus用于內部開發,你應該配置一個包含了release版和snapshot的single nexus group。為此,你需要添加snapshot倉庫到你的public group,并且在你的Maven的settings.xml中添加如下內容:
<settings> ? <mirrors> ? ? <mirror> ? ? ? <!--This sends everything else to /public --> ? ? ? <id>nexus</id> ? ? ? <mirrorOf>*</mirrorOf> ? ? ? <url>http://localhost:8081/nexus/content/groups/public</url> ? ? </mirror> </mirrors> ? <profiles> ? <profile> ? ? <id>nexus</id> ? ? <!--Enable snapshots for the built in central repo to direct --> ? ? <!--all requests to nexus via the mirror --> ? ? <repositories> ? ? ? <repository> ? ? ? ? <id>central</id> ? ? ? ? <url>http://central</url> ? ? ? <releases> ? ? ? ? <enabled>true</enabled> ? ? ? </releases> ? ? ? <snapshots> ? ? ? ? <enabled>true</enabled> ? ? ? </snapshots> ? ? </repository> ? </repositories> ? ? <pluginRepositories> ? ? <pluginRepository> ? ? ? <id>central</id> ? ? ? <url>http://central</url> ? ? ? <releases> ? ? ? ? <enabled>true</enabled> ? ? ? </releases> ? ? ? <snapshots> ? ? ? ? <enabled>true</enabled> ? ?</snapshots> ? </pluginRepository> </pluginRepositories> </profile> </profiles> ? <activeProfiles> <!--make the profile active all the time --> <activeProfile>nexus</activeProfile> </activeProfiles> </settings> |
在上面的配置信息中,我們定義了一個single group:nexus。 然后配置了repository以及pluginRepository并以id "central"命名,這個配置重寫了super pom的同名的倉庫。我們更改了倉庫讓其支持snapshots并且使用了偽造的URL替換了默認URL,這樣nexus group能夠包含release以及snapshot版的artifacts,并且maven可以使用它們。
?
? ??為Missing Denpendence添加一個自定義的倉庫
? ? 如果你曾經配置了maven settings.xml來列出nexus的public group里所有的倉庫,你可能遇到你的項目無法在本地nexus取得artifacts信息。這很有可能是因為你嘗試去構建在pom中定義的自定義倉庫或者snapshotRepository。
? ? 首先登陸nexus,默認的用戶名和密碼是admin/admin123,按圖示進行選擇:
?
在彈出框中選擇Proxy Repository,填寫表單后保存即可。
?
?
第二種方式也是nexus官方文檔的做法,但是我沒有配置成功,總是報無法找到xxx, 因為趕工期,也就暫時擱置不研究了。
?
?
轉載于:https://www.cnblogs.com/dycg/archive/2013/05/29/3106968.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的配置Maven使用Nexus的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java环境json哪些事?
- 下一篇: 《Getting Real》读书笔记