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

相关推荐
风月歌12 小时前
小程序项目之超市售货管理平台小程序源代码(源码+文档)
java·微信小程序·小程序·毕业设计·源码
SimonKing12 小时前
浅谈银行系统对接中的安全和槽点
java·后端·程序员
tryxr12 小时前
Java 中 this 关键字的使用场景
java·开发语言·类与对象·this关键字
Coder_Boy_12 小时前
Spring 核心思想与企业级最佳特性(思想级)
java·后端·spring
毕设源码-朱学姐12 小时前
【开题答辩全过程】以 红色旅游网站为例,包含答辩的问题和答案
java
Catcharlotte12 小时前
反射和设计模式
java
要开心吖ZSH12 小时前
Spring Boot + JUnit 5 + Mockito + JaCoCo 单元测试实战指南
java·spring boot·junit·单元测试
原来是好奇心12 小时前
Spring源码深度解析(一):Spring的设计灵魂——控制反转与依赖注入的演进之路
java·spring·源码
艾莉丝努力练剑12 小时前
Al Ping免费上新:GLM-4.7 && MiniMaxM2.1重磅上线,附独家使用教程
java·大数据·linux·运维·人工智能·python
济南壹软网络科技有限公司12 小时前
IM源码架构深度解析:构建高并发、私有化的企业级通讯底座
java·架构·即时通讯源码·通讯im·企业级im