gradle排除依赖_如何从Gradle中的所有依赖项中排除库
gradle排除依赖
我正在使⽤Spring Boot。 默认情况下,Spring Boot带有Logback。 我想使⽤log4j(出于任何原因..)
为了做到这⼀点,我不得不排除logback并添加新的log4j依赖项:
在此软件包中“隐藏”了logback:
compile("org.springframework.boot:spring-boot-starter:$springBootVersion")
{
exclude module: 'org.springframework.boot:spring-boot-starter-logging'
}
compile("org.springframework.boot:spring-boot-starter-log4j:$springBatchVersion")
现在,当您尝试运⾏应⽤程序时,会出现以下异常:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/dev/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.7.10/b3eeae7d1765f988a1f45ea81517191315c69c9e/slf4j-log4j12-1.7 SLF4J: Found binding in [jar:file:/C:/dev/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.1.2/b316e9737eea25e9ddd6d88eaeee76878045c6b2/logba
现在,我们必须查看Gradle的依赖关系树,以查看隐藏了logback的位置以消除它。
查看gradle依赖关系树的简单命令:
gradle -q dependencies web:dependencies --configuration compile
* web代表您的模块名称。
输出的快照视图:
Project :web - web
------------------------------------------------------------
springboot aop
compile - Compile classpath for source set 'main'.
+--- org.springframework.boot:spring-boot-starter-actuator:1.2.2.RELEASE
| +--- org.springframework.boot:spring-boot-starter:1.2.2.RELEASE
| | +--- org.springframework.boot:spring-boot:1.2.2.RELEASE
| | | +--- org.springframework:spring-core:4.1.5.RELEASE
| | | | \--- commons-logging:commons-logging:1.2
| | | \--- org.springframework:spring-context:4.1.5.RELEASE
| | | +--- org.springframework:spring-aop:4.1.5.RELEASE
| | | | +--- aopalliance:aopalliance:1.0
| | | | +--- org.springframework:spring-beans:4.1.5.RELEASE
| | | | | \--- org.springframework:spring-core:4.1.5.RELEASE (*)
| | | | \--- org.springframework:spring-core:4.1.5.RELEASE (*)
| | | +--- org.springframework:spring-beans:4.1.5.RELEASE (*)
| | | +--- org.springframework:spring-core:4.1.5.RELEASE (*)
| | | \--- org.springframework:spring-expression:4.1.5.RELEASE
| | | \--- org.springframework:spring-core:4.1.5.RELEASE (*)
| | +--- org.springframework.boot:spring-boot-autoconfigure:1.2.2.RELEASE
| | | +--- org.springframework.boot:spring-boot:1.2.2.RELEASE (*)
| | | \--- org.yaml:snakeyaml:1.14
| | +--- org.springframework.boot:spring-boot-starter-logging:1.2.2.RELEASE
| | | +--- org.slf4j:jcl-over-slf4j:1.7.10
| | | | \--- org.slf4j:slf4j-api:1.7.10
| | | +--- org.slf4j:jul-to-slf4j:1.7.10
| | | | \--- org.slf4j:slf4j-api:1.7.10
| | | +--- org.slf4j:log4j-over-slf4j:1.7.10
| | | | \--- org.slf4j:slf4j-api:1.7.10
| | | \--- mycompany:logback-classic:1.1.2
| | | +--- mycompany:logback-core:1.1.2
| | | \--- org.slf4j:slf4j-api:1.7.6 -> 1.7.10
| | +--- org.springframework:spring-core:4.1.5.RELEASE (*)
| | \--- org.yaml:snakeyaml:1.14
| +--- org.springframework.boot:spring-boot-actuator:1.2.2.RELEASE
我们可以从我们的⼀个依赖项中到⼀个弹出的logback实例:
mycompany:logback-core:1.1.2
(我发现logback show在其他依赖项中)。
现在我们有两个选择:
1. 在Indecency树中排除每个Logback的路由
2. 使⽤配置范围内的排除(更简便的⽅法)
因此,转到您的adle并添加以下内容:
configurations {
}
⽽已。 你的噩梦结束了。 如果再次检查依赖关系树,您将不再看到任何logback。
翻译⾃:
gradle排除依赖

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。