Maven Helper插件——實現一鍵Maven依賴沖突問題


業余在一個SpringBoot項目集成Swagger2時,啟動過程一直出現以下報錯信息——

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

出現這個問題,大概猜測到,應該是Maven依賴沖突導致的,忽然想到,是否有可以檢查maven依賴沖突的插件呢,一查發現還真有,而且極方便。

這個Idea插件,叫Maven Helper,根據File -> Settings -> Plugins -> Marketplace 輸入Maven Helper即可找到。
image
下載后,重啟IDEA,這時點擊pom.xml文件,會發現多了一欄【Dependency Analyzer】——
image

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

image
選中對應想去除的包,右擊即可一鍵exclusion——

image
再切換至Text欄,即可發現已經自動增加了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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM