第5章:座標和依賴/5.9 最佳實踐/5.9.3 依賴關係檢視
- 依賴關係檢視
- 檢視依賴列表:mvn dependency:list
- 概念:查詢某個專案所有的依賴關係,平級顯示
- 舉例:
不區分依賴關係,全部羅列出來
[INFO] org.springframework:spring-beans:jar:2.5.6:compile 第一個依賴
[INFO] commons-logging:commons-logging:jar:1.1.1:compile 第二個依賴
[INFO] org.mybatis:mybatis:jar:3.4.5:compile 第三個依賴
[INFO] aopalliance:aopalliance:jar:1.0:compile
[INFO] org.springframework:spring-core:jar:2.5.6:compile 第五個依賴
[INFO] org.springframework:spring-context:jar:2.5.6:compile 第六個依賴
- 檢視依賴樹:mvn dependency:tree
- 概念:查詢某個專案依賴的上下級關係
- 舉例:
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building JavaMaven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ java-maven ---
[INFO] com.test:java-maven:jar:0.0.1-SNAPSHOT 本專案
[INFO] +- org.mybatis:mybatis:jar:3.4.5:compile
[INFO] +- org.springframework:spring-core:jar:2.5.6:compile 第二個依賴
[INFO] | \- commons-logging:commons-logging:jar:1.1.1:compile 第二個依賴的依賴
[INFO] +- org.springframework:spring-beans:jar:2.5.6:compile 第三個依賴
[INFO] \- org.springframework:spring-context:jar:2.5.6:compile 第四個依賴
[INFO] \- aopalliance:aopalliance:jar:1.0:compile 第四個依賴的依賴
- 依賴分析:mvn dependency:analyze
- 概念:會羅列出已被使用或者未被使用的依賴
- 舉例:
未使用的依賴,按順序只列出直接依賴,沒有傳遞性依賴
[WARNING] Unused declared dependencies found:
[WARNING] org.mybatis:mybatis:jar:3.4.5:compile
[WARNING] org.springframework:spring-core:jar:2.5.6:compile
[WARNING] org.springframework:spring-beans:jar:2.5.6:compile
[WARNING] org.springframework:spring-context:jar:2.5.6:compile