maven項目jar包依賴沖突問題,我平時不是很在意,但是面試要考,學習新知識總是好的;
依賴沖突產生原因:
maven項目需要A、B兩個依賴,A依賴需要C依賴,B依賴需要C依賴,這時候maven會下載兩個C依賴,然后遵循路徑最短原則,使用路徑最短的C依賴,而另一個C依賴則不會使用;
依賴沖突解決辦法:
1. idea打開pom文件,右鍵點擊Show Dependencies選項,查看依賴沖突;紅色箭頭標注表示沖突的依賴;
2. 使用exclusions標簽可以讓maven不拉取重復的依賴;
<exclusions> <exclusion> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> </exclusion> <exclusion> <artifactId>commons-lang3</artifactId> <groupId>org.apache.commons</groupId> </exclusion> <exclusion> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> </exclusion> </exclusions>
推薦閱讀:https://blog.csdn.net/weixin_43718648/article/details/103562645