gradle排除依赖_如何从Gradle中的所有依赖项中排除库
生活随笔
收集整理的這篇文章主要介紹了
gradle排除依赖_如何从Gradle中的所有依赖项中排除库
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
gradle排除依賴
我正在使用Spring Boot。 默認情況下,Spring Boot帶有Logback。 我想使用log4j(出于任何原因..)
為了做到這一點,我不得不排除logback并添加新的log4j依賴項:
在此軟件包中“隱藏”了logback:
compile("org.springframework.boot:spring-boot-starter:$project.ext.springBootVersion"){exclude module: 'org.springframework.boot:spring-boot-starter-logging' }compile("org.springframework.boot:spring-boot-starter-log4j:$project.ext.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.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/dev/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.1.2/b316e9737eea25e9ddd6d88eaeee76878045c6b2/logback-classic-1.1.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]現在,我們必須查看Gradle的依賴關系樹,以查看隱藏了logback的位置以消除它。
查看gradle依賴關系樹的簡單命令:
gradle -q dependencies web:dependencies --configuration compile* web代表您的模塊名稱。
輸出的快照視圖:
Project :web - web------------------------------------------------------------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在其他依賴項中)。
現在我們有兩個選擇:
因此,轉到您的build.gradle并添加以下內容:
configurations {compile.exclude group:'ch.qos.logback' }而已。 你的噩夢結束了。 如果再次檢查依賴關系樹,您將不再看到任何logback。
翻譯自: https://www.javacodegeeks.com/2015/03/how-to-exclude-libraries-from-all-dependencies-in-gradle.html
gradle排除依賴
總結
以上是生活随笔為你收集整理的gradle排除依赖_如何从Gradle中的所有依赖项中排除库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java自动推断类型_推断:Facebo
- 下一篇: linux的安装教程(linux引导安装