[英]Gradle shared dependency version issue
我對Gradle構建所采用的依賴關系版本有問題。 我使用Gradle 4.6。
我有一個自己開發的庫,它帶來了實用工具之王。 我們稱它為utils.jar。 我還開發了另一個庫,用於與Web服務進行通信。 我們稱它為network.jar。 然后,我開發一個需要network.jar依賴項和utils.jar依賴項的項目。 但是我需要一個utils.jar版本,該版本高於network.jar使用的版本。
My project
|
|-> network.jar:v1
| |
| |
| -> utils.jar:v1
|
-> utils.jar:v2
這是網絡庫的build.gradle
dependencies {
compile "com.mycompany:utils:1"
}
這是我的項目的build.gradle
dependencies {
compile "com.mycompany:network:1" // pull utils.jar:1
compile "com.mycompany:utils:2" // I need utils.jar:2 in my project
}
在我的項目中,當我嘗試使用utils.jar的v2時,v2中引入的新方法不可用。 在IntelliJ中,我可以在類路徑中看到utils.jar v2,但是當我嘗試使用com.mycompany.utils.CollectionUtils類時,它使用嵌入在network.jar庫(v1)中的utils代碼,而不是使用utils v2。
因此,當此依賴項導入到我的項目中時,我試圖從network.jar中顯式刪除utils.jar(v1)。 build.gradle在我的項目中:
dependencies {
compile("com.mycompany:network:1") {
exclude group: 'com.mycompany', module: 'utils'
}
compile "com.mycompany:utils:2"
}
但是utils v1代碼仍嵌入在network.jar代碼中,這是代替v2使用的代碼。
如何使Gradle理解我想要的是utils v2,而不是由network.jar拉出的utils v1?
我發現了錯誤。 我在Maven回購network.jar lib並將其發布為胖子。 因此,utils.jar的代碼始終嵌入在network.jar的代碼中。
如果人們犯同樣的錯誤,我會發布解決方案。
我從network.jar build.gradle文件中刪除了它:
jar {
// Remove that to not build a fat-jar in this case
// from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
manifest {
attributes 'Implementation-Title': 'Utils',
'Implementation-Version': version,
'Created-By': 'Myself'
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.