Gradle - 无法追踪传递依赖

时间:2016-04-28 03:09:42

标签: spring gradle spring-boot

我有两个模块:common和domain。域是共同的依赖。在域中,我正在尝试添加最新版本的Spring Data Elasticsearch,但它一直在恢复旧版本。我的域的build.gradle文件如下所示:

域build.gradle

apply plugin: 'spring-boot'

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE")
}
}

dependencies {
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-redis")
compile("org.springframework.data:spring-data-elasticsearch:2.0.1.RELEASE")
compile 'org.slf4j:slf4j-api'
compile 'com.google.guava:guava:19.0'

compile 'com.google.code.gson:gson:2.4'
testCompile "org.mockito:mockito-core:1.+"
}

这里的elasticsearch版本是2.0.1.RELASE但是,如果我共同运行dependencyInsight,它会检索1.3.4.RELEASE:

gradle dependencyInsight --dependency elasticsearch --configuration compile
:common:dependencyInsight

Download https://repo1.maven.org/maven2/org/springframework/data/spring-data-elasticsearch/1.3.4.RELEASE/spring-data-elasticsearch-1.3.4.RELEASE.pom

org.elasticsearch:elasticsearch:1.5.2 (selected by rule) 
\--- org.springframework.data:spring-data-elasticsearch:1.3.4.RELEASE
 \--- project :domain
      \--- compile

org.springframework.data:spring-data-elasticsearch:1.3.4.RELEASE (selected by rule)

org.springframework.data:spring-data-elasticsearch:2.0.1.RELEASE -> 1.3.4.RELEASE
\--- project :domain
 \--- compile

common build.gradle

apply plugin: 'spring-boot'


buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE")
}
}    

dependencies {
compile project(':domain')
compile 'com.google.code.gson:gson:2.4'
compile 'org.owasp.encoder:encoder:1.2'
compile 'com.ning:async-http-client:1.9.31'
compile 'org.slf4j:slf4j-api'
compile 'org.springframework.security:spring-security-core'
compile 'org.springframework.security:spring-security-acl:4.0.3.RELEASE'
compile 'javax.mail:javax.mail-api:1.5.4'
compile 'com.sun.mail:javax.mail:1.5.4'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile "org.mockito:mockito-core:1.+"
}

版本1.3.4.RELEASE是否有理由替换2.0.1.RELEASE?

1 个答案:

答案 0 :(得分:4)

您正在将Spring Boot的Gradle插件应用到您的公共项目中。这意味着它的依赖关系管理将控制项目依赖项的版本。要获得所需的Spring Data Elasticsearch版本,可以通过添加以下内容来覆盖Boot的依赖关系管理:

dependencyManagement {
    dependencies {
        dependency 'org.springframework.data:spring-data-elasticsearch:2.0.1.RELEASE'
    }
}