Spring Boot / Gradle / Querydsl项目具有相同的依赖关系,该依赖关系依赖于另一个依赖关系的不同版本 [英] Spring Boot/Gradle/Querydsl project has the same dependency dependent on different versions of another dependency

查看:205
本文介绍了Spring Boot / Gradle / Querydsl项目具有相同的依赖关系,该依赖关系依赖于另一个依赖关系的不同版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am having problems adding Querydsl to my Spring Boot project. I have the following dependencies in my build.gradle file:

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'
}

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

The project builds fine, but when I run it, I get the following error:

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窗口显示以下内容:

The Gradle window in IntelliJ shows the following:

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

Why does each instance of com.querydsl:querydsl-core:4.2.1 depend on a different version of guava?

推荐答案

番石榴的18.0版本来自querydsl,而20.0的版本来自spring-fox swagger。

The version 18.0 of Guava comes from querydsl and the 20.0 comes from spring-fox swagger.

spring-fox库希望调用番石榴20.0版的方法。但从18.0开始。 (因为有两个在类路径中具有不同版本的番石榴库)

spring-fox library expected that method of guava version 20.0 to be called. but called from 18.0. (because there are two guava library that has difference version in classpath)

您可以使用以下代码来避免番石榴的冲突版本。

you can use the following code to avoid conflict version of 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 / Gradle / Querydsl项目具有相同的依赖关系,该依赖关系依赖于另一个依赖关系的不同版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆