Java 如何用gradle排除可传递依赖项并用另一个替换它

Java 如何用gradle排除可传递依赖项并用另一个替换它,java,gradle,configuration,Java,Gradle,Configuration,我的处境和他相似 (JodaTime和大于1.8u60的Java版本之间的错误) 所以我需要的是: 升级到JodaTime 2.8.1版或更高版本 问题是:JodaTime在我的项目中是一个可传递的依赖项 it中使用的构建自动化工具是gradle。需要帮助来处理它 构建脚本: buildscript { ext { springBootVersion = '1.2.4.RELEASE' } repositories { mavenCentr

我的处境和他相似 (JodaTime和大于1.8u60的Java版本之间的错误)

所以我需要的是:

  • 升级到JodaTime 2.8.1版或更高版本
  • 问题是:JodaTime在我的项目中是一个可传递的依赖项
  • it中使用的构建自动化工具是gradle。需要帮助来处理它

    构建脚本:

    buildscript {
        ext {
            springBootVersion = '1.2.4.RELEASE'
        }
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
            classpath("io.spring.gradle:dependency-management-plugin:0.5.1.RELEASE")
            classpath("org.flywaydb:flyway-gradle-plugin:3.2.1")
        }
    }
    
    apply plugin: 'java'
    apply plugin: 'idea'
    apply plugin: 'eclipse'
    apply plugin: 'spring-boot' 
    apply plugin: 'io.spring.dependency-management' 
    apply plugin: 'org.flywaydb.flyway'
    
    jar {
        baseName = 'xxxx'
        version = 'alpha'
    }
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
    
        compile("org.springframework.boot:spring-boot-starter-data-jpa:1.2.4.RELEASE")
        compile("org.springframework.boot:spring-boot-starter-aop:1.2.4.RELEASE")
        compile("org.springframework.boot:spring-boot-starter-web:1.2.4.RELEASE")
        compile("org.springframework.boot:spring-boot-starter-freemarker:1.2.4.RELEASE")
        compile("com.amazonaws:aws-java-sdk:1.10.2")
        compile("com.stripe:stripe-java:1.33.0")
        compile("org.flywaydb:flyway-core:3.2.1")
        compile("com.jolbox:bonecp:0.8.0.RELEASE")
    
        runtime("org.postgresql:postgresql:9.4-1201-jdbc41")
    
        testCompile("org.springframework.boot:spring-boot-starter-test:1.2.4.RELEASE")
    }
    
    dependencyManagement {
        imports { 
            mavenBom "org.springframework.cloud:spring-cloud-starter-parent:1.0.2.RELEASE" 
        }
    }
    
    eclipse {
        classpath {
             containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
             containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
        }
    }
    
    task wrapper(type: Wrapper) {
        gradleVersion = '2.3'
    }
    

    将transitive设置为false,并在依赖项之间设置所需的包,而不是在transitive下载中设置的包。

    您需要在
    依赖项
    块中更改以下代码:

    compile("com.amazonaws:aws-java-sdk:1.10.2") {
         exclude group: 'joda-time', module: 'joda-time'
    }
    compile("joda-time:joda-time:2.8.1")
    

    看来这是可以做到的。您是否可以共享build.gradle脚本或至少它的相关部分?@Opal………这样您将排除给定依赖项的所有可传递依赖项-这并不总是您想要/需要的。