1. 程式人生 > >Maven傳遞依賴無法引入解決辦法

Maven傳遞依賴無法引入解決辦法

今天一個傳遞依賴問題搞了我半天,終於搞明白原因了。一個jar包A依賴了httpclient,然後另一個jar包B引入A,在IDEA裡面只能看到依賴A,不管咋樣都看不到依賴httpclient。

我在IDEA的專案B裡面,打包後在控制檯發現一個告警:

the POM for A is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details

原來是jar包A的pom依賴有問題。

問題排查

在應用B的根目錄列印依賴樹:

mvn dependency:tree>tree.txt

應用依賴樹中出現如下警告。警告顯示:應用引入的依賴包無效,依賴包中傳遞依賴項不可用,可以通過開啟debug獲取更多資訊。

[WARNING] the POM for A is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details... 

然後我開啟debug功能,重新列印依賴樹:

mvn -X dependency:tree>tree.txt

開啟maven debug功能後,警告後緊跟了一條錯誤資訊,如下。

[WARNING] The POM for com.huawei.dc.security:security-sdk-https:jar:1.0-SNAPSHOT is invalid, transitive dependencies (if any) will not be available: 2 problems were encountered while building the effective model for com.huawei.dc.security:security-sdk-https:1.0-SNAPSHOT
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-configuration-processor:jar is missing. @ 
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-autoconfigure:jar is missing. @ 
...

原來是A包中引入的另外的spring-boot-autoconfigure沒加版本號,這個我以為能繼承父pom的版本號,發現這裡不生效。具體原因我再分析。

解決方案

在A中把版本號補上重新發布