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即可找到。

下载后,重启IDEA,这时点击pom.xml文件,会发现多了一栏【Dependency Analyzer】------

切换至【Dependency Analyzer】栏,在搜索框输入冲突包guava,即会出现,guava都被哪些包依赖了,当多个组件包都依赖了同一个包但又不同版本时,很容易久出现各种冲突。红色部分即是导致启动报异常的地方,可见,springfox-core已经依赖的是20.0包,但其他还依赖18版本的包,这里可以把报错提示的18.0版本的通过exclusion去除即可。

选中对应想去除的包,右击即可一键exclusion------

再切换至Text栏,即可发现已经自动增加了exclusions模块------

XML 复制代码
<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>
相关推荐
秋饼12 小时前
LangChain4j + Java 实现企业级 Text-to-SQL 智能问数系统:从自然语言到安全可控的数据洞察
java·ai·技术分享·后端开发
Escalating_xu12 小时前
【C++ STL简介】从六大组件到容器、迭代器与算法协作
java·c++·算法
何以解忧,唯有..12 小时前
Python os模块详解:文件与目录操作指南
java·服务器·python
Csxyzj12 小时前
kubernetes集群部署方法
java·linux·kubernetes
SQL-First布道者12 小时前
全面解构传统持久层框架,拥抱真正的 SQL-First
java·数据库·spring boot·sql·spring·mybatis·spring jdbc
小蒜学长13 小时前
vue旅游攻略网站(代码+数据库+LW)
java·数据库·vue.js·spring boot·后端·旅游
凤山老林13 小时前
轻量级规则引擎落地:Spring Boot 集成 LiteFlow 实现动态业务编排与热更新
java·spring boot·后端·规则引擎·liteflow
夏贰四13 小时前
管控数据加载调度如何规避任务冲突?数据加载运维监控体系该如何搭建?
java·大数据·运维
山甫aa13 小时前
JavaWeb后端开发学习手册
java·开发语言·数据库·学习·mysql·springboot·web
鱼鳞_14 小时前
热门八股-JVM
java·jvm