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 的依赖即可。

相关推荐
茶本无香28 分钟前
RequestContextFilter介绍
java·spring·filter·requestcontext
iナナ42 分钟前
初识JVM
java·jvm
m0_570466411 小时前
代码随想录算法训练营第二十八天 | 买卖股票的最佳实际、跳跃游戏、K次取反后最大化的数组和
java·开发语言·算法
ST.J2 小时前
swing笔记
java·笔记
菩提树下的凡夫2 小时前
瑞芯微RV1126目标识别算法Yolov8的部署应用
java·算法·yolo
爱隐身的官人2 小时前
新后端漏洞(上)- Java RMI Registry反序列化漏洞
java·反序列化漏洞
叫我阿柒啊2 小时前
从Java全栈到前端框架:一次真实的面试对话与技术解析
java·javascript·typescript·vue·springboot·react·前端开发
晚安里2 小时前
Spring 框架(IoC、AOP、Spring Boot) 的必会知识点汇总
java·spring boot·spring
爱隐身的官人2 小时前
新后端漏洞(上)- Aapache Tomcat AJP 文件包含漏洞(CVE-2020-1938)
java·tomcat·ajp
@CLoudbays_Martin113 小时前
为什么动态视频业务内容不可以被CDN静态缓存?
java·运维·服务器·javascript·网络·python·php