Maven解決包衝突

依賴樹

$ 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解決了衝突後的樹(解決衝突的策略是:就近原則,即離根近的依賴被採納)html

原始依賴樹

$ 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參數則能夠顯示原始的依賴樹,讓你顯式地看出某個包都在哪些枝幹上出現了。java

遞歸依賴的關係列的算是比較清楚了,每行都是一個jar包,根據縮進能夠看到依賴的關係。git

  • 最後寫着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)定義以下:github

[groupId]:[artifactId]:[type]:[version]

每一個部分(冒號分割的部分)是支持*通配符的,若是要指定多個格式則能夠用,分割,如:apache

mvn dependency:tree -Dincludes=javax.servlet,org.apache.*

demo:segmentfault

$ 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] ------------------------------------------------------------------------

也能夠直接查詢一個artifactidapi

mvn dependency:tree -Dverbose -Dincludes=:notify-common

清空本地倉庫依賴包

mvn dependency:purge-local-repository

默認狀況下,插件對全部傳遞依賴項進行操做。這意味着插件能夠在開始清除過程以前下載某些缺乏的依賴項以收集完整的依賴關係樹信息。maven

actTransitively

爲避免此預下載步驟,能夠將插件配置爲僅使用「actTranstively」參數對項目的直接依賴性進行操做。測試

mvn dependency:purge-local-repository -DactTransitively=false

actTransitively是否應該對全部傳遞依賴性起做用。默認值爲true。ui

設置爲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也無效,會清除所有本地依賴,不知道咋回事。

參考:

用dependency插件解決依賴包衝突

清除本地存儲庫依賴項

用dependency:tree查看maven引入jar包的傳遞依賴

Apache Maven Dependency Plugin

相關文章
相關標籤/搜索