chia7712 commented on code in PR #22201:
URL: https://github.com/apache/kafka/pull/22201#discussion_r3491163510


##########
build.gradle:
##########
@@ -1879,11 +1898,35 @@ project(':clients') {
     archivesName = "kafka-clients"
   }
 
+  apply plugin: 'java-test-fixtures'
+
   configurations {
     generator
     shadowed
   }
 
+  // Rewire test fixtures dependencies to avoid depending on the shadow JAR:
+  // java-test-fixtures creates dependencies testImplementation -> 
testFixturesApi -> (main artifact)
+  // It prefers the main artifact over the raw main classpath so that 
dependents on fixtures get the same
+  // packaged artifact as production consumers. In this module the main 
artifact is the shadow JAR,
+  // so this creates a test dependency on createVersionFile breaking 
AppInfoParserTest, and worse:
+  // test code is compiled against the original packages, but the shadow JAR 
contains relocated bytecode,
+  // causing runtime errors for various tests. To fix this, we rewire the test 
fixtures dependency to the raw
+  // source set output, so tests continue to use compiled classes and original 
dependencies instead of the shadow JAR.
+  // 
https://github.com/gradle/gradle/blob/v9.4.1/platforms/jvm/plugins-jvm-test-fixtures/src/main/java/org/gradle/api/plugins/JavaTestFixturesPlugin.java#L89-L90
+  afterEvaluate {
+    configurations.testFixturesApi.dependencies.removeIf { dep ->
+      dep instanceof ProjectDependency && dep.name == project.name
+    }
+    dependencies {
+      testFixturesApi files(sourceSets.main.output.classesDirs)

Review Comment:
   We should revisit those tests instead of hacking the dependencies. The test 
code in the clients module should NOT depend on `io.opentelemetry`, and that 
can be addressed by moving the `io.opentelemetry`-related code to 
`ClientTelemetryUtils`. It is not perfect, but it's better than a hack in 
`build.gradle`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to