maven 依赖冲突异常分析

异常如下

text 复制代码
Description:

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

    com.google.common.cache.CacheBuilder.initialCapacity(CacheBuilder.java:353)

The following method did not exist:

    com.google.common.base.Preconditions.checkState(ZLjava/lang/String;I)V

The calling method's class, com.google.common.cache.CacheBuilder, was loaded from the following location:

    jar:file:/Users/Zhuanz/Documents/software/apache-maven-3.8.1/maven-repository/com/google/guava/guava/30.1-jre/guava-30.1-jre.jar!/com/google/common/cache/CacheBuilder.class

The called method's class, com.google.common.base.Preconditions, is available from the following locations:

    jar:file:/Users/Zhuanz/Documents/software/apache-maven-3.8.1/maven-repository/com/google/collections/google-collections/1.0/google-collections-1.0.jar!/com/google/common/base/Preconditions.class
    jar:file:/Users/Zhuanz/Documents/software/apache-maven-3.8.1/maven-repository/com/google/guava/guava/30.1-jre/guava-30.1-jre.jar!/com/google/common/base/Preconditions.class

The called method's class hierarchy was loaded from the following locations:

    com.google.common.base.Preconditions: file:/Users/Zhuanz/Documents/software/apache-maven-3.8.1/maven-repository/com/google/collections/google-collections/1.0/google-collections-1.0.jar


Action:

Correct the classpath of your application so that it contains compatible versions of the classes com.google.common.cache.CacheBuilder and com.google.common.base.Preconditions

异常栈分析

text 复制代码
com.google.common.cache.CacheBuilder.initialCapacity方法调用com.google.common.base.Preconditions.checkState

com.google.common.cache.CacheBuilder.initialCapacity来自于/Users/Zhuanz/Documents/software/apache-maven-3.8.1/maven-repository/com/google/guava/guava/30.1-jre/guava-30.1-jre.jar

com.google.common.base.Preconditions.checkState方法来自于/Users/Zhuanz/Documents/software/apache-maven-3.8.1/maven-repository/com/google/collections/google-collections/1.0/google-collections-1.0.jar
分析过程
1、打印 classloader 发现类加载器一样
2、mvn:dependency 得到如下截图,由于 google-collections 比 guava 层级高,因此会加在google-collections jar 包中的Preconditions类
3、查看两个 jar 包中的字节码
javap -v -classpath guava-30.1-jre.jar com.google.common.base.Preconditions | grep -A 10 "checkState"
javap -v -classpath google-collections-1.0.jar com.google.common.base.Preconditions | grep -A 10 "checkState"
对比发现com.google.common.base.Preconditions类中的 checkState 方法没有com.google.common.base.Preconditions.checkState(ZLjava/lang/String;I)V

解决办法:去除 google-collection 的依赖即可。

相关推荐
沙雕不是雕又菜又爱玩几秒前
基于springboot的超市收银系统
java·spring boot·intellij-idea
SunnyDays10111 分钟前
使用 Java 高效删除 Excel 空白行与空白列
java·删除 excel 空白行·删除 excel 空白列
笨手笨脚の2 分钟前
Java 性能优化
java·jvm·数据库·性能优化·分布式锁·分布式事务·并发容器
l软件定制开发工作室6 分钟前
Spring开发系列教程(32)——Spring Boot开发
java·spring boot·后端·spring
DolphinScheduler社区10 分钟前
Apache DolphinScheduler 3.4.1 发布,新增任务分发超时检测
java·数据库·开源·apache·海豚调度·大数据工作流调度
黑眼圈子14 分钟前
Java正则表达式基础知识
java·开发语言·正则表达式
iPadiPhone15 分钟前
性能优化的“快车道”:Spring @Async 注解深度原理与大厂实战
java·后端·spring·面试·性能优化
彭于晏Yan15 分钟前
JsonProperty注解的access属性
java·spring boot
Mr.朱鹏21 分钟前
分布式-redis集群架构
java·redis·分布式·后端·spring·缓存·架构
予枫的编程笔记22 分钟前
【面试专栏|Java并发编程】Java并发锁对比:synchronized与Lock,底层原理+适用场景详解
java·synchronized·java面试·java并发编程·并发锁·面试干货·lock接口