2017-05-15 33 views
1

我正在使用Gradle 3.4.1。爲什麼我的庫的編譯依賴關係泄漏?

我有一個使用Gradle java-library插件構建的庫(我們稱之爲utils),這會生成一個很好的JAR文件。這是依賴關係部分:

dependencies { 
// public API 
api group: "org.postgresql", name: "postgresql", version: "9.2-1004-jdbc4"  
api group: "log4j", name: "log4j", version: "1.2.17" 

// implementation specific 
implementation group: "commons-configuration", name: "commons-configuration" , version: "1.10" 
implementation group: "commons-lang", name: "commons-lang" , version: "2.6" 
} 

現在我的項目包括這個庫,以及一些其他的Apache共享庫:

dependencies { 
compile group: "com.foo", name: "utils", version: "6.+", changing: true 
compile group: "org.apache.commons", name: "commons-lang3", version: "3.5" 
compile group: "commons-io", name: "commons-io" , version: "2.5" 
} 

在我的類路徑的項目,我現在有commons-lang庫以及commons-lang3庫,雖然我指定適當的依賴關係爲implementation!根據文檔https://docs.gradle.org/3.4.1/userguide/java_library_plugin.html這應該是正確的方法。

這裏是我的項目的依賴上市:

default - Configuration for default artifacts. 
+--- com.foo:utils:6.+ -> 6.0.0 
| +--- org.postgresql:postgresql:9.2-1004-jdbc4 
| +--- log4j:log4j:1.2.17 
| +--- commons-configuration:commons-configuration:1.10 
| | +--- commons-lang:commons-lang:2.6 
| | \--- commons-logging:commons-logging:1.1.1 
| \--- commons-lang:commons-lang:2.6 
+--- org.apache.commons:commons-lang3:3.5 
\--- commons-io:commons-io:2.5 

我在做什麼錯?我如何擺脫外部依賴關係commons-langcommons-configuration

+0

需要注意的是執行依賴仍然最終將成爲運行時依賴 - 他們需要在運行時類路徑。 –

回答

0

有幾種排除傳遞依賴的方法,在幾個問題和gradle文檔中都有介紹。

configurations { 
    compile.transitive = false 
} 

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

dependencies { 
    compile ('foo:bar:0.1') { 
     exclude group: "org.slf4j", module: "slf4j-log4j12" 
    } 
} 
相關問題