spring-boot - Spring Boot/Gradle/Querydsl项目有相同的依赖依赖不同版本的另一个依赖

标签 spring-boot gradle guava dependency-management querydsl

我在将 Querydsl 添加到我的 Spring Boot 项目时遇到问题。我的 build.gradle 文件中有以下依赖项:

dependencies {
    annotationProcessor 'com.querydsl:querydsl-apt:4.1.3:jpa'
    annotationProcessor 'org.springframework.boot:spring-boot-starter-data-jpa'

    implementation 'com.querydsl:querydsl-jpa:4.1.3'

    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
    implementation 'org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.3.RELEASE'
    implementation 'org.springframework.cloud:spring-cloud-config-client:2.1.0.RELEASE'

    implementation 'mysql:mysql-connector-java'

    implementation 'io.springfox:springfox-swagger2:2.9.2'
    implementation 'io.springfox:springfox-swagger-ui:2.9.2'
    implementation 'io.springfox:springfox-bean-validators:2.9.2'
    implementation group: 'org.latencyutils', name: 'LatencyUtils', version: '2.0.3'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-inline:2.23.4'
}

项目构建正常,但是当我运行它时,出现以下错误:

An attempt was made to call the method com.google.common.collect.FluentIterable.concat(Ljava/lang/Iterable;Ljava/lang/Iterable;)Lcom/google/common/collect/FluentIterable; but it does not exist. Its class, com.google.common.collect.FluentIterable, is available from the following locations:

    jar:file:/C:/Users/me/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/18.0/cce0823396aa693798f8882e64213b1772032b09/guava-18.0.jar!/com/google/common/collect/FluentIterable.class
    jar:file:/C:/Users/me/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/20.0/89507701249388e1ed5ddcf8c41f4ce1be7831ef/guava-20.0.jar!/com/google/common/collect/FluentIterable.class

It was loaded from the following location:

    file:/C:/Users/me/.gradle/caches/modules-2/files-2.1/com.google.guava/guava/18.0/cce0823396aa693798f8882e64213b1772032b09/guava-18.0.jar


Action:

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

IntelliJ 中的 Gradle 窗口显示如下:

enter image description here

为什么 com.querydsl:querydsl-core:4.2.1 的每个实例都依赖于不同版本的 Guava ?

最佳答案

Guava 18.0版本来自querydsl,20.0版本来自spring-fox swagger。

spring-fox 库期望调用 guava 版本 20.0 的方法。但从 18.0. (因为类路径中有两个不同版本的 Guava 库)

可以使用下面的代码来避免guava版本冲突。

// QueryDsl
implementation("com.querydsl:querydsl-jpa:${querydslVersion}")
annotationProcessor("org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final")
annotationProcessor("com.querydsl:querydsl-apt:${querydslVersion}:jpa") {
    exclude group: "come.google.guava"
}
annotationProcessor("com.google.guava:guava:20.0")

关于spring-boot - Spring Boot/Gradle/Querydsl项目有相同的依赖依赖不同版本的另一个依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57529427/

相关文章:

java - Axis 1.4 问题(无法加载 [META-INF/services/org.apache.axis.EngineConfigurationFactor)

java - Android gradle :app:packageDebug FAILED: class org. bouncycaSTLe.asn1.ASN1Primitive 覆盖 final方法等于

java - 为什么我在 Intellij 上编辑配置时看到无法解析主方法上的符号?

java - 在固定超时内缓存单个对象的最佳方法是什么?

java - Spark 1.5 和 datastax-ddc-3.2.1 Cassandra 依赖项 Jars?

java - 如何在 XML 中使用 Spring Java 属性默认值

Spring Data Rest用户存储库BCCrypt密码

java - 没有这样的方法错误:

java - gradle 传递依赖下载本地 ivy

java - Guava 的 RangeSet/Range 中没有 "size"的概念?