SNAPSHOT包上傳nexus成功,下載失敗
阿新 • • 發佈:2021-11-10
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
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
成功構建
感悟:
紙上得來終覺淺,絕知此事要躬行。
只有當你會了,理解了,融會貫通了,才能感覺到豁然開朗。