如何用 gradle 排除传递依赖并将其替换为另一个

How to exclude transitive dependencies with gradle and substitute it with another

我的情况与 this 相似 (JodaTime 和大于 1.8u60 的 Java 版本之间的错误)。

所以我需要的是:

  1. 正在升级到 JodaTime 版本 2.8.1 或更高版本。
  2. 问题是:JodaTime 是我项目中的传递依赖。

其中使用的构建自动化工具是gradle。需要帮助来处理它。

buildscript:

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

将传递性设置为 false,并在您的依赖项之间设置您需要的包,而不是传递性下载中的包。

您需要更改 dependencies 块中的以下代码:

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