Gradle排除依赖性极度困惑

时间:2016-07-15 20:43:33

标签: java gradle groovy spring-boot

我非常困惑,我不是一个gradle专家,不熟悉Groovy语法。问题是,我想要排除我的日志库中的传递依赖,但当我尝试使用gradle bootRun启动我的应用程序时,看起来我不能因为有某种语法错误而我无法弄清楚这是什么。这是我得到的错误:

>gradle bootRun

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\workspace\tictactoe\build.gradle' line: 55

* What went wrong:
A problem occurred evaluating root project 'tictactoe'.
> No signature of method: java.util.LinkedHashMap.call() is applicable for argument types: (build_bkiihj275q6h9zzyz2rjvcelk$_run_closure3$_closure7) values: [build_bkiihj275q6h9zzyz2
rjvcelk$_run_closure3$_closure7@7d42404e]
Possible solutions: wait(), any(), wait(long), any(groovy.lang.Closure), take(int), max(groovy.lang.Closure)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 5.678 secs

这是我的gradle.build的一部分,我添加了所有依赖项:

compile (
                [group: 'org.slf4j', name: 'jcl-over-slf4j', version: '1.6.2'],
                [group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'],
                [group: 'org.springframework.boot', name: 'spring-boot-starter-jetty'],
                [group: 'org.springframework.boot', name: 'spring-boot-starter-logging'],
                [group: 'org.springframework', name: 'spring-context-support'],
                [group: 'org.apache.commons', name: 'commons-lang3', version: commonsLangVersion],
                [group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion],
                [group: 'org.slf4j', name: 'slf4j-log4j12', version:'1.7.10']
                        {
                            exclude group: 'ch.qos.logback', module: 'logback-classic'
                        },
                [group: 'log4j', name: 'log4j', version:'1.2.17'],
                [group: 'com.mashape.unirest', name: 'unirest-java', version: unirestVersion],
                [group: 'com.cedarsoftware', name: 'json-io', version: jsonioVersion]
        )

2 个答案:

答案 0 :(得分:1)

应该这样做。

[
    [group: 'org.slf4j', name: 'jcl-over-slf4j', version: '1.6.2'],
    [group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'],
    [group: 'org.springframework.boot', name: 'spring-boot-starter-jetty'],
    [group: 'org.springframework.boot', name: 'spring-boot-starter-logging'],
    [group: 'org.springframework', name: 'spring-context-support'],
    [group: 'org.apache.commons', name: 'commons-lang3', version: commonsLangVersion],
    [group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion],
    [group: 'log4j', name: 'log4j', version:'1.2.17'],
    [group: 'com.mashape.unirest', name: 'unirest-java', version: unirestVersion],
    [group: 'com.cedarsoftware', name: 'json-io', version: jsonioVersion]
].each {
    compile it
}

compile 'org.slf4j:slf4j-log4j12:1.7.10', {
    exclude module: 'logback-classic'
}

您可以更进一步,使其更简单

[
    'org.slf4j:jcl-over-slf4j:1.6.2', 
    'log4j:log4j:1.2.17', 
    'foo:bar:0.1'
].each { compile it }

答案 1 :(得分:1)

您可能希望全局排除项目的回溯。 最简单的方法是将以下内容添加到项目build.gradle中:

configurations.all {
    exclude group: "ch.qos.logback", module: "logback-classic"
}

如果要排除该组中的所有内容而不仅仅是特定工件(logback-classic),则可以省略module。像这样:

configurations.all {
    exclude group: "ch.qos.logback"
}