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

相关推荐
珹洺1 分钟前
数据库系统概论(十)SQL 嵌套查询 超详细讲解(附带例题表格对比带你一步步掌握)
java·数据库·sql
写bug写bug2 分钟前
彻底搞懂管道-过滤器模式
java·后端·架构
深色風信子34 分钟前
Eclipse 插件开发 5.2 编辑器 获取当前编辑器
java·eclipse·编辑器·eclipse 编辑器获取·eclipse 插件
fajianchen39 分钟前
Tomcat优化篇
java·tomcat
代码丰40 分钟前
在 SpringBoot+Tomcat 环境中 线程安全问题的根本原因以及哪些变量会存在线程安全的问题。
java·spring boot·后端
花月C1 小时前
复杂业务场景下 JSON 规范设计:Map<String,Object>快速开发 与 ResponseEntity精细化控制HTTP 的本质区别与应用场景解析
java·前端·后端·http
橘子青衫1 小时前
Java并发编程:FutureTask解析与实战
java·后端
!chen1 小时前
鲲鹏Arm+麒麟V10 K8s 离线部署教程
java·arm开发·kubernetes
用户15246671668951 小时前
理解 Java 内存模型和 happens-before
java·后端
程序员岳焱1 小时前
12.Java 对象冷冻术:从用户登录到游戏存档的序列化实战
java·后端·编程语言