浏览代码

[Example Builds] Fix Jarhell in example build due to version conflict (#135598) (#135647)

* [Example Builds] Fix Jarhell in example build due to version conflict

In test framework we expose org.hamcrest:hamcrest. Transitively junit and the randomized runner
expose hamcrest-core transitive dependencies. This makes jarHell task fail as those jars share
common class files.

We exclude hamcrest core now explicitly as transitive dependency in the generated pom for
test framework as we already include a superset of this by having a direct dependency on
hamcrest which includes hamcrest-core

* Cleanup

* Rework excluded transitive dependencies
Rene Groeschke 1 周之前
父节点
当前提交
eeff8cccd5
共有 1 个文件被更改,包括 13 次插入13 次删除
  1. 13 13
      test/framework/build.gradle

+ 13 - 13
test/framework/build.gradle

@@ -10,15 +10,6 @@
 apply plugin: 'elasticsearch.build'
 apply plugin: 'elasticsearch.publish'
 
-configurations {
-  // we do not want to expose a version conflict in transitive dependencies by
-  // bringing in different versions of hamcrest and hamcrest-core.
-  // Therefore we exclude transitive deps on hamcrest-core here as we have a direct
-  // dependency on a newer version.
-  runtimeElements {
-    exclude group: 'org.hamcrest', module: 'hamcrest-core'
-  }
-}
 dependencies {
   api project(":client:rest")
   api project(':modules:transport-netty4')
@@ -26,13 +17,22 @@ dependencies {
   api project(":server")
   api project(":libs:cli")
   api project(":libs:entitlement:bridge")
-  api "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
-  api("junit:junit:${versions.junit}") {
-//    exclude group: 'org.hamcrest'
+  api ("com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}") {
+    exclude group: "junit", module: "junit"
   }
+
+  // we do not want to expose a version conflict in transitive dependencies by
+  // bringing in different versions of dependencies.
+  // Therefore we exclude mismatches in our transitive dependencies explicitly.
+  // This also avoids jarHell issues with different hamcrest related dependencies
+  // like hamcrest and hamcrest-core
   api "org.hamcrest:hamcrest:${versions.hamcrest}"
+  api("junit:junit:${versions.junit}") {
+    exclude group: 'org.hamcrest', module: 'hamcrest-core'
+  }
   api("org.apache.lucene:lucene-test-framework:${versions.lucene}") {
-//    exclude group: 'org.hamcrest'
+    exclude group: "junit", module: "junit"
+    exclude group: 'com.carrotsearch.randomizedtesting', module: 'randomizedtesting-runner'
   }
   api "org.apache.lucene:lucene-codecs:${versions.lucene}"
   api "commons-logging:commons-logging:${versions.commonslogging}"