依賴樹
$ mvn dependency:tree
[WARNING]
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: 'properties' (position: START_TAG seen ...</profile>\n\t <properties>..
@85:18) @ C:\Users\qhong\.m2\settings.xml, line 85, column 18
[WARNING]
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< com.xuxueli:xxl-excel >------------------------
[INFO] Building xxl-excel 1.1.2-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ xxl-excel ---
[INFO] com.xuxueli:xxl-excel:jar:1.1.2-SNAPSHOT
[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- org.apache.poi:poi:jar:3.17:compile
[INFO] | +- commons-codec:commons-codec:jar:1.10:compile
[INFO] | \- org.apache.commons:commons-collections4:jar:4.1:compile
[INFO] \- org.apache.poi:poi-ooxml:jar:3.17:compile
[INFO] +- org.apache.poi:poi-ooxml-schemas:jar:3.17:compile
[INFO] | \- org.apache.xmlbeans:xmlbeans:jar:2.6.0:compile
[INFO] | \- stax:stax-api:jar:1.0.1:compile
[INFO] \- com.github.virtuald:curvesapi:jar:1.04:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.572 s
[INFO] Finished at: 2019-04-19T11:24:17+08:00
[INFO] ------------------------------------------------------------------------
mvn:dependency:tree
打印出來的是 maven解決了沖突后的樹(解決沖突的策略是:就近原則,即離根近的依賴被采納)
原始依賴樹
$ mvn dependency:tree -Dverbose
[WARNING]
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: 'properties' (position: START_TAG seen ...</profile>\n\t <properties>... @85:18) @ C:\Users\qhong\.m2\settings.xml, line 85, column 18
[WARNING]
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< com.xuxueli:xxl-excel >------------------------
[INFO] Building xxl-excel 1.1.2-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ xxl-excel ---
[INFO] com.xuxueli:xxl-excel:jar:1.1.2-SNAPSHOT
[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- org.apache.poi:poi:jar:3.17:compile
[INFO] | +- commons-codec:commons-codec:jar:1.10:compile
[INFO] | \- org.apache.commons:commons-collections4:jar:4.1:compile
[INFO] \- org.apache.poi:poi-ooxml:jar:3.17:compile
[INFO] +- (org.apache.poi:poi:jar:3.17:compile - omitted for duplicate)
[INFO] +- org.apache.poi:poi-ooxml-schemas:jar:3.17:compile
[INFO] | \- org.apache.xmlbeans:xmlbeans:jar:2.6.0:compile
[INFO] | \- stax:stax-api:jar:1.0.1:compile
[INFO] \- com.github.virtuald:curvesapi:jar:1.04:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.636 s
[INFO] Finished at: 2019-04-19T11:13:29+08:00
[INFO] ------------------------------------------------------------------------
通過指定
-Dverbose
參數則可以顯示原始的依賴樹,讓你顯式地看出某個包都在哪些枝干上出現了。
遞歸依賴的關系列的算是比較清楚了,每行都是一個jar包,根據縮進可以看到依賴的關系。
- 最后寫着compile的就是編譯成功的。
- 最后寫着omitted for duplicate的就是有jar包被重復依賴了,但是jar包的版本是一樣的。
- 最后寫着omitted for conflict with xxxx的,說明和別的jar包版本沖突了,而該行的jar包不會被引入。比如上面有一行最后寫着omitted for conflict with 1.8.3,那么該行的commons-beanutils:jar:1.8.0不會被引入,只有1.8.3版本的會被引入。
篩選依賴樹
只想看依賴樹中包含 groupId 為 javax.serlet 的枝干
mvn dependency:tree -Dincludes=javax.servlet
不想看依賴樹中包含 groupId 為 javax.serlet 的枝干
mvn dependency:tree -Dexcludes=javax.servlet
參數的格式(pattern)定義如下:
[groupId]:[artifactId]:[type]:[version]
每個部分(冒號分割的部分)是支持*
通配符的,如果要指定多個格式則可以用,
分割,如:
mvn dependency:tree -Dincludes=javax.servlet,org.apache.*
demo:
$ mvn dependency:tree -Dverbose -Dincludes=org.apache.poi
[WARNING]
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: 'properties' (position: START_TAG seen ...</profile>\n\t <properties>... @85:18) @ C:\Users\qhong\.m2\settings.xml, line 85, column 18
[WARNING]
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< com.xuxueli:xxl-excel >------------------------
[INFO] Building xxl-excel 1.1.2-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ xxl-excel ---
[INFO] com.xuxueli:xxl-excel:jar:1.1.2-SNAPSHOT
[INFO] +- org.apache.poi:poi:jar:3.17:compile
[INFO] \- org.apache.poi:poi-ooxml:jar:3.17:compile
[INFO] +- (org.apache.poi:poi:jar:3.17:compile - omitted for duplicate)
[INFO] \- org.apache.poi:poi-ooxml-schemas:jar:3.17:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.635 s
[INFO] Finished at: 2019-04-19T11:17:21+08:00
[INFO] ------------------------------------------------------------------------
也可以直接查詢一個artifactid
mvn dependency:tree -Dverbose -Dincludes=:notify-common
清空本地倉庫依賴包
mvn dependency:purge-local-repository
默認情況下,插件對所有傳遞依賴項進行操作。這意味着插件可以在開始清除過程之前下載某些缺少的依賴項以收集完整的依賴關系樹信息。
actTransitively
為避免此預下載步驟,可以將插件配置為僅使用“actTranstively”參數對項目的直接依賴性進行操作。
mvn dependency:purge-local-repository -DactTransitively=false
actTransitively是否應該對所有傳遞依賴性起作用。默認值為true。
設置為false就僅對項目的直接依賴項進行刪除,不進行設置就全部刪除,包括依賴包的依賴包。。。
reResolve
mvn dependency:purge-local-repository -DreResolve=false
reResolve是否重新解析依賴關系(就是刪除以后是否重新下載依賴包)
--fail-at-end
mvn dependency:purge-local-repository -DactTransitively=false -DreResolve=false --fail-at-end
忽略錯誤( --fail-at-end
)。 對於那些有一些依賴關系混亂的項目,或者依賴於一些內部的倉庫(這種情況發生),這樣做有時是有用的。
過濾刪除依賴包
mvn dependency:purge-local-repository -Dinclude=org.slf4j:slf4j-api,org.slf4j:log4j-over-slf4j
手動清除
手動清除不屬於當前項目依賴關系樹的特定依賴項
mvn dependency:purge-local-repository -DmanualIncludes=org.apache:apache
經過測試發現,清理本地代碼的include,exclude全無效,不會清除本地任何依賴,includes,exculdes也無效,會清除全部本地依賴,不知道咋回事。