日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

gradle排除依赖_如何从Gradle中的所有依赖项中排除库

發布時間:2023/12/3 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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在其他依賴項中)。

現在我們有兩個選擇:

  • 在Indecency樹中排除每個Logback的路由
  • 使用配置范圍內的排除(更簡便的方法)
  • 因此,轉到您的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中的所有依赖项中排除库的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。