Maven Helper插件——實(shí)現(xiàn)一鍵Maven依賴沖突問題

業(yè)余在一個(gè)SpringBoot項(xiàng)目集成Swagger2時(shí),啟動(dòng)過程一直出現(xiàn)以下報(bào)錯(cuò)信息——

An attempt was made to call a method that does not exist. The attempt was made from the following location:

springfox.documentation.schema.DefaultModelDependencyProvider.dependentModels(DefaultModelDependencyProvider.java:79)

The following method did not exist:

com.google.common.collect.FluentIterable.concat(Ljava/lang/Iterable;Ljava/lang/Iterable;)Lcom/google/common/collect/FluentIterable;

The method's class, com.google.common.collect.FluentIterable, is available from the following locations:

jar:file:/C:/Users/92493/.m2/repository/com/google/guava/guava/18.0/guava-18.0.jar!/com/google/common/collect/FluentIterable.class

The class hierarchy was loaded from the following locations:

com.google.common.collect.FluentIterable: file:/C:/Users/92493/.m2/repository/com/google/guava/guava/18.0/guava-18.0.jar

Action:

Correct the classpath of your application so that it contains a single, compatible version of com.google.common.collect.FluentIterable

出現(xiàn)這個(gè)問題,大概猜測到,應(yīng)該是Maven依賴沖突導(dǎo)致的,忽然想到,是否有可以檢查maven依賴沖突的插件呢,一查發(fā)現(xiàn)還真有,而且極方便。

這個(gè)Idea插件,叫Maven Helper,根據(jù)File -> Settings -> Plugins -> Marketplace 輸入Maven Helper即可找到。


image.png

下載后,重啟IDEA,這時(shí)點(diǎn)擊pom.xml文件,會(huì)發(fā)現(xiàn)多了一欄【Dependency Analyzer】——


image.png

切換至【Dependency Analyzer】欄,在搜索框輸入沖突包guava,即會(huì)出現(xiàn),guava都被哪些包依賴了,當(dāng)多個(gè)組件包都依賴了同一個(gè)包但又不同版本時(shí),很容易久出現(xiàn)各種沖突。紅色部分即是導(dǎo)致啟動(dòng)報(bào)異常的地方,可見,springfox-core已經(jīng)依賴的是20.0包,但其他還依賴18版本的包,這里可以把報(bào)錯(cuò)提示的18.0版本的通過exclusion去除即可。


image.png

選中對應(yīng)想去除的包,右擊即可一鍵exclusion——

image.png

再切換至Text欄,即可發(fā)現(xiàn)已經(jīng)自動(dòng)增加了exclusions模塊——

<dependency>
    <groupId>io.shardingsphere</groupId>
    <artifactId>sharding-jdbc-spring-namespace</artifactId>
    <version>3.1.0</version>
    <exclusions>
        <exclusion>
            <artifactId>guava</artifactId>
            <groupId>com.google.guava</groupId>
        </exclusion>
    </exclusions>
</dependency>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容