maven 依赖树
maven 依賴樹
- idea 可視化使用
- 查看依賴樹
- 解決沖突
- 命令使用
- 輸出依賴樹
- 擴(kuò)展
idea 可視化使用
查看依賴樹
如圖,點(diǎn)擊 maven,展開項(xiàng)目,可以看到 Dependencies。這些是項(xiàng)目引入的 jar 包,但是看不出依賴沖突問題。
點(diǎn)擊 Show Dependencies ,即可打開項(xiàng)目依賴樹圖。
- 藍(lán)色線:正常依賴
- 紅色虛線:同一個包被多次引用,編譯可過
- 紅色實(shí)線:依賴沖突,會導(dǎo)致編譯出錯
解決沖突
- 右鍵 紅色實(shí)線 指向的 jar 包,右鍵選擇 Exclude ,然后 idea 右下角就會彈出 提示你 Import Changes。
- 點(diǎn)擊 Import Changes ,查看 pom.xml 文件,相關(guān)的 dependency 依賴已經(jīng)多了 excluion 標(biāo)簽了,即去除該依賴的意思。
命令使用
輸出依賴樹
兩種方式召喚出命令工具,并執(zhí)行命令查看 maven 依賴樹。
1、點(diǎn)擊 idea 的 maven -> Execute Maven Goal,彈出 maven 命令提示列表,輸入dependency:tree
2、Terminal 終端輸入 mvn dependency:tree
enter. 即可看到這種格式的 jar 依賴樹啦。
擴(kuò)展
- mvn dependency:tree 命令必須要在 pom.xml 同級目錄下執(zhí)行
- 查看最全的傳遞依賴,加 -Dverbose ,如 mvn dependency:tree -Dverbose
- 過濾依賴,加 -Dincludes=groupId[:artifactId][:version] ,如
mvn dependency:tree -Dverbose -Dincludes=org.springframework:spring-tx - 保存依賴樹,加 >xxx.txt ,如 mvn dependency:tree -Dverbose>dependency.txt
- idea 中可通過使用 maven helper 插件便捷處理大量沖突,參考 idea 中解決maven 包沖突的問題(maven helper)
參考與感謝
http://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html
https://maven.apache.org/plugins/maven-dependency-plugin/examples/filtering-the-dependency-tree.html
總結(jié)
- 上一篇: linux ftp主动和被动模式切换命令
- 下一篇: Julia常用包简介