【问题标题】:How do I write this Maven exclusion code in Gradle?如何在 Gradle 中编写此 Maven 排除代码?
【发布时间】:2015-08-12 22:30:48
【问题描述】:

我正在尝试在 Spring Boot 项目中使用 Betamax 的最新(主)版本,我收到了错误 SLF4J: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError.

所以我查看了this question 的最佳答案,它说通过这样做来排除冲突依赖项:

<exclusions>
  <exclusion> 
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
  </exclusion>
  <exclusion> 
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
  </exclusion>
</exclusions> 

但我的项目使用的是 Gradle,所以我必须将其转换为 Gradle,我真的不知道我在做什么。我看着this post 并尝试像这样搞砸它

dependencies {
    ...
    compile('org.slf4j') {
        exclude module: 'slf4j-log4j12'
    }
}

但似乎没有任何效果。谁能帮我找出正确的语法?非常感谢任何帮助。

如果它有帮助的话,我的依赖块目前看起来像这样:

dependencies {
    testCompile 'org.springframework.boot:spring-boot-starter-test:1.2.1.RELEASE'
    testCompile 'org.codehaus.groovy:groovy-all:2.3.3'
    testCompile 'co.freeside.betamax:betamax-proxy:2.0-SNAPSHOT'
    testCompile 'co.freeside.betamax:betamax-junit:2.0-SNAPSHOT'
    compile 'org.springframework.boot:spring-boot-starter-log4j2:1.2.1.RELEASE'
    compile 'org.springframework.boot:spring-boot-starter-web:1.2.1.RELEASE'
    compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.2.1.RELEASE'
    compile 'org.springframework.boot:spring-boot-starter-tomcat:1.2.1.RELEASE'
    compile 'org.apache.tomcat.embed:tomcat-embed-jasper'
    compile 'com.domingosuarez.boot:spring-boot-starter-jade4j:0.2'
    compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.4.0'
    compile 'com.mashape.unirest:unirest-java:1.4.5'
    runtime 'mysql:mysql-connector-java:5.1.34'
    runtime 'net.kencochrane.raven:raven-log4j2:6.0.0'
}

【问题讨论】:

  • slf4j-log4j12 中的依赖是什么?我没看到。无论如何,这是您要排除的依赖项(不是 org.slf4j)。比如是raven-log4j2,那么runtime('net.kencochrane.raven:raven-log4j2:6.0.0') { exclude module: 'slf4j-log4j12' }
  • @DonBottstein,这行得通。谢谢!

标签: java maven gradle spring-boot betamax


【解决方案1】:

谢谢你们的帮助,伙计们。通过遵循 Don Bottstein 的建议并执行以下操作,我能够修复错误:

testCompile('co.freeside.betamax:betamax-proxy:2.0-SNAPSHOT') {
    exclude module: 'slf4j-log4j12'
}
testCompile('co.freeside.betamax:betamax-junit:2.0-SNAPSHOT') {
    exclude module: 'slf4j-log4j12'
}

【讨论】:

    【解决方案2】:

    正确的语法是:

    dependencies {
        compile("org.gradle.test.excludes:api:1.0") {
            exclude group: "org.springframework", module: "spring-core"
        }
    }
    

    地点:

    • org.gradle.test.excludes:api:1.0 是一个 groupId:artifactId:version
    • 组:“org.springframework”,模块:“spring-core”是组:groupId,模块:artifactId

    【讨论】:

    • 我收到了这个错误:Could not GET 'http://oss.jfrog.org/oss-snapshot-local/org/gradle/test/excludes/api/1.0/api-1.0.pom'. Received status code 409 from server: Conflict
    • 这是一个例子,你必须用你拥有的信息替换值。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-11
    • 1970-01-01
    相关资源
    最近更新 更多