Gradle 排除依赖非常混乱
Posted
技术标签:
【中文标题】Gradle 排除依赖非常混乱【英文标题】:Gradle excluding dependency extremely confused 【发布时间】:2016-11-19 04:10:33 【问题描述】:我非常困惑,我不是 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]
)
【问题讨论】:
【参考方案1】:您可能希望从您的项目中全局排除 logback。
最简单的方法是将以下内容添加到项目的build.gradle
:
configurations.all
exclude group: "ch.qos.logback", module: "logback-classic"
如果您想排除该组中的所有内容而不仅仅是特定的工件 (logback-classic
),您可以省略 module
。像这样:
configurations.all
exclude group: "ch.qos.logback"
【讨论】:
【参考方案2】:应该这样做。
[
[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
【讨论】:
您可能希望从您的项目中全局排除 logback。以上是关于Gradle 排除依赖非常混乱的主要内容,如果未能解决你的问题,请参考以下文章
Android Gradle 插件Android 依赖管理 ⑥ ( 依赖冲突处理 | transitive 依赖传递设置 | exclude 依赖排除设置 | force 强制指定依赖库 )