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

相关推荐
深栈解码35 分钟前
JMM深度解析(三) volatile实现机制详解
java·后端
liujing102329291 小时前
Day04_刷题niuke20250703
java·开发语言·算法
Brookty1 小时前
【MySQL】JDBC编程
java·数据库·后端·学习·mysql·jdbc
能工智人小辰1 小时前
二刷 苍穹外卖day10(含bug修改)
java·开发语言
DKPT1 小时前
Java设计模式之结构型模式(外观模式)介绍与说明
java·开发语言·笔记·学习·设计模式
缘来是庄1 小时前
设计模式之外观模式
java·设计模式·外观模式
知其然亦知其所以然2 小时前
JVM社招面试题:队列和栈是什么?有什么区别?我在面试现场讲了个故事…
java·后端·面试
harmful_sheep2 小时前
Spring 为何需要三级缓存解决循环依赖,而不是二级缓存
java·spring·缓存
星辰大海的精灵2 小时前
如何确保全球数据管道中的跨时区数据完整性和一致性
java·后端·架构
大大。2 小时前
van-tabbar-item选中active数据变了,图标没变
java·服务器·前端