[英]gradle force version of transitive dependency not working. No exclude, override or force seems to apply
我與傳遞依賴有沖突。 覆蓋,排除或強制無濟於事。 我還能做些什么才能將正確版本的庫放入jar? 完整代碼dan be。 找到了https://github.com/geoHeil/gradle-dependency-resolution,但其主要部分如下所述。
執行
./gradlew shadowJar
禁用了geomesa依賴項(引入了過時的typesafe / lightbend配置庫版本):
dependencies {
compile "com.github.kxbmap:configs_2.11:0.4.4"
//compile "org.locationtech.geomesa:geomesa-hbase-spark-runtime_2.11:2.0.1"
}
並執行罐子
java -jar build/libs/gradleThing-all.jar
輸出
hello
my config is: Success(Job1Configuration(frequencyCounting))
啟用依賴項時:
./gradlew shadowJar
java -jar build/libs/gradleThing-all.jar
它失敗了
hello
Exception in thread "main" java.lang.Exception: Failed to start. There is a problem with the configuration: Vector([extract] com.typesafe.config.Config.hasPathOrNull(Ljava/lang/String;)Z)
哪個與配置庫的過時版本有關, 如何解決Typesafe配置上的NoSuchMethodError? 。 還通過以下方式確認:
gradle dependencyInsight --dependency om.typesafe:config
> Task :dependencyInsight
com.typesafe:config:1.3.1 (conflict resolution)
variant "runtime" [
Requested attributes not found in the selected variant:
org.gradle.usage = java-api
]
\--- com.github.kxbmap:configs_2.11:0.4.4
\--- compileClasspath
com.typesafe:config:1.2.1 -> 1.3.1
variant "runtime" [
Requested attributes not found in the selected variant:
org.gradle.usage = java-api
]
+--- org.locationtech.geomesa:geomesa-convert-avro_2.11:2.0.1
| \--- org.locationtech.geomesa:geomesa-convert-all_2.11:2.0.1
| +--- org.locationtech.geomesa:geomesa-tools_2.11:2.0.1
| | \--- org.locationtech.geomesa:geomesa-hbase-spark-runtime_2.11:2.0.1
| | \--- compileClasspath
...
如何將傳遞依賴項固定到所需的1.3.3版本?
嘗試設置:
compile("org.locationtech.geomesa:geomesa-hbase-spark-runtime_2.11:2.0.1") {
exclude group: 'com.typesafe', module: 'config'
}
並重新運行jar再次失敗,並出現相同的問題。
implementation("com.typesafe:config")
constraints {
implementation("com.typesafe:config:1.3.3") {
because 'previous versions miss a method https://stackoverflow.com/questions/40610816/how-to-resolve-nosuchmethoderror-on-typesafe-config'
}
}
implementation('com.typesafe:config:1.3.3') {
force = true
}
或類似:
configurations.all {
resolutionStrategy {
force 'com.typesafe:config:1.3.3'
}
}
沒有給出正確的版本。
所有變體均以相同的錯誤失敗
怎么了? 必須有一種強制所需版本的方法。
您遇到的問題與您所描述的完全相反。
你在你的項目中的所有嘗試不同的東西,確保版本com.typesafe:config
是一個1.3.x
。
但是,在添加org.locationtech.geomesa:geomesa-hbase-spark-runtime_2.11:2.0.1
您會org.locationtech.geomesa:geomesa-hbase-spark-runtime_2.11:2.0.1
一些依賴項,該依賴項已經具有com.typesafe:config
的類,但來自1.2
行。 當您創建胖子罐時,該版本將覆蓋1.3
行中的類。
可以通過解壓縮胖罐並運行來看到這一點:
$ javap com/typesafe/config/Config.class | grep hasPath
public abstract boolean hasPath(java.lang.String);
表明確實缺少hasPathOrNull
方法。
https://issues.apache.org/jira/browse/SPARK-9441中暗示了該陰影問題。
鑒於此,簡單的方法-如果可能的話-將"com.github.kxbmap:configs_2.11
降級到依賴com.typesafe:config:1.2.x
另一個解決方案是准確找出哪個胖子包含這些胖子,並查看是否可以將其從自己的胖子中排除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.