java - 如何使用 gradle 排除传递依赖并用另一个替代

标签 java gradle configuration

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

所以我需要的是:

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

其中使用的构建自动化工具是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'
}

最佳答案

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

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

关于java - 如何使用 gradle 排除传递依赖并用另一个替代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32226149/

相关文章:

configuration - IntelliJ配置目录

java - DatePickerDialog Holo 样式在 Android 7 Nougat 上失败

java - centOS上tomcat多个web应用不同域名

java - 为多个远程调试连接配置 Tomcat?

gradle - 有没有一种方法可以配置Gradle插件来执行带有构建的任务?

android - React Native : What's the difference between gradle references in gradle-wrapper. 属性和 build.gradle?

java - 加载已捆绑在 .jar 中的文件?

java - 如何在 Hadoop 上更新或写入文件系统?

java - 我正在开发一款 Android 电子邮件客户端应用程序。我在读取多部分消息正文时遇到问题

gradle - Findbugs Gradle 插件不会使构建失败