x-SNAPSHOT.jar上傳nexus成功,下載失敗
兩個項目:項目a與項目b
項目b需要引入項目a的 a-api.jar。
dependency信息
<!-- b/ pom.xml -->
<!-- 引入項目a的api -->
<groupId>com.wsy.a</groupId>
<artifactId>a-api</artifactId>
<version>1.0-SNAPSHOT</version>
a-api.jar已經deploy至nexus中,但是b中引入失敗。
問題定位:
第一步:
cd
至項目b目錄下,使用mvn install -X
查看詳細構建日志,驗證
- 讀取的配置文件沒有問題;
- mirror中的鏡像地址沒有問題,是我的nexus地址;
第二步:
再次去nexus中查看,地址 ip:port/repository/maven-public/
可在瀏覽器中直接打開,上面確實是有a-api.jar
文件
第三步:
繼續看mvn install -X
的日志信息,發現查找的庫始終是central
,沒有去查分組中的maven-snapshot
庫,
在maven-public
重新加入maven-snapshot
庫,並且刷新索引,然而還是沒用。
第四步:
基本可以確認問題是
從nexus中下載snapshot包失敗,猜想本地上傳的jar都會下載失敗。
搜索發現一句話
Maven內置的插件遠程倉庫配置,關閉了對SNAPSHOT的支持,防止不穩定的構建
所以需要添加對SNAPSHOT
的支持
怎么添加對SNAPSHOT的支持?
在 settings.xml 中設置屬性 profiles --> profile --> repositories --> repository --> snapshots --> true
第五步
使用profile來定義倉庫屬性,增加對SNAPSHOT的支持
<!-- .m2/settings.xml -->
<!-- 去掉mirro配置,統一使用 profile repository 來管理遠程倉康 -->
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus-snapshots</id>
<url>http://ip:port/repository/maven-public/</url>
<!-- 添加對`SNAPSHOT`的支持 -->
<snapshots>
<enabled>true</enabled>
</snapshots>
<!-- 添加對`RELEASE`的支持 -->
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<!-- 與 profile.id 對應 -->
<activeProfile>nexus</activeProfile>
<!-- <activeProfile>aliyun</activeProfile> -->
</activeProfiles>
mvn install
成功構建
感悟:
紙上得來終覺淺,絕知此事要躬行。
只有當你會了,理解了,融會貫通了,才能感覺到豁然開朗。