Maven依赖Guava前后版本兼容问题,Correct the classpath of your application so that it contains a single

这是项目启动时报错

***************************
APPLICATION FAILED TO START
***************************

Description:

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

    io.grpc.Metadata$Key.validateName(Metadata.java:629)

The following method did not exist:

    com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;CLjava/lang/Object;)V

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

    jar:file:/H:/.m2/repository/com/google/guava/guava/19.0/guava-19.0.jar!/com/google/common/base/Preconditions.class

It was loaded from the following location:

    file:/H:/.m2/repository/com/google/guava/guava/19.0/guava-19.0.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of com.google.common.base.Preconditions

现在看看版本中都有哪些Jar依赖了 Guava
Maven依赖Guava前后版本兼容问题,Correct the classpath of your application so that it contains a single_第1张图片
查看你依赖下都用了哪些版本的Guava,只看应用了哪个版本,中间的子依赖嵌套就不展示了。。

服务 Maven 依赖
├── spring-cloud-starter-alibaba-nacos-discovery
–> 19.0
–> 16.0
├──自建通用工具包
–> 20.0 guava

现在就是没有向后兼容问题,那么把19.0,16.0,20.0的Guava依赖全部排除,在项目下直接依赖最后一个版本

<dependency>
            <groupId>com.alibaba.cloudgroupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
            <exclusions>
                <exclusion>
                    <groupId>com.google.guavagroupId>
                    <artifactId>guavaartifactId>
                exclusion>
            exclusions>
dependency>
<dependency>
            <groupId>com.google.cloudgroupId>
            <artifactId>google-cloud-speechartifactId>
            <exclusions>
                <exclusion>
                    <groupId>com.google.guavagroupId>
                    <artifactId>guavaartifactId>
                exclusion>
            exclusions>
dependency>
<dependency>
            <groupId>com.google.guavagroupId>
            <artifactId>guavaartifactId>
            <version>20.0version>
dependency>

问题解决,这样会有一个问题,未来引进新的jar,依然可能会遇到前后兼容的问题
Maven依赖Guava前后版本兼容问题,Correct the classpath of your application so that it contains a single_第2张图片

参考文档

Spring Boot获取加载的jar是哪个版本-提供解决版本冲突问题思路,guava不向后兼容问题

你可能感兴趣的:(其他)