Move caffeine patching to instrumentation-api-caching
MODIFY
instrumentation-api-caching/build.gradle.kts
instrumentation-api-caching/build.gradle.kts
@@ -20,6 +20,11 @@ dependencies {
shadowInclude("com.blogspot.mydailyjava:weak-lock-free")
}
+// patch inner class from Caffeine to avoid ForkJoinTask from being loaded too early in the javaagent
+val patch by sourceSets.creating {
+ java {}
+}
+
tasks {
shadowJar {
configurations = listOf(shadowInclude)
@@ -32,7 +37,15 @@ tasks {
val extractShadowJar by registering(Copy::class) {
dependsOn(shadowJar)
- from(zipTree(shadowJar.get().archiveFile))
+
+ // replace caffeine class with our patched version
+ from(zipTree(shadowJar.get().archiveFile)) {
+ exclude("io/opentelemetry/instrumentation/api/internal/shaded/caffeine/cache/BoundedLocalCache\$PerformCleanupTask.class")
+ }
+ from(patch.output) {
+ include("io/opentelemetry/instrumentation/api/internal/shaded/caffeine/cache/BoundedLocalCache\$PerformCleanupTask.class")
+ }
+
into("build/extracted/shadow")
// prevents empty com/github/benmanes/caffeine/cache path from ending up in instrumentation-api
includeEmptyDirs = false

RENAME
javaagent-bootstrap/src/patch/java/io/opentelemetry/instrumentation/api/internal/shaded/caffeine/cache/BoundedLocalCache.java
instrumentation-api-caching/src/patch/java/io/opentelemetry/instrumentation/api/internal/shaded/caffeine/cache/BoundedLocalCache.java
MODIFY
instrumentation-api/build.gradle.kts
instrumentation-api/build.gradle.kts
@@ -33,6 +33,7 @@ dependencies {
compileOnly("com.google.auto.value:auto-value-annotations")
annotationProcessor("com.google.auto.value:auto-value")
+ testCompileOnly(project(":instrumentation-api-caching"))
testImplementation(project(":testing-common"))
testImplementation("org.mockito:mockito-core")
testImplementation("org.mockito:mockito-junit-jupiter")

RENAME
javaagent-bootstrap-tests/src/test/java/io/opentelemetry/instrumentation/api/caching/PatchCaffeineTest.java
instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/caching/PatchCaffeineTest.java
DELETE
javaagent-bootstrap-tests/build.gradle.kts
-plugins {
- id("otel.java-conventions")
-}
-
-dependencies {
- // For testing javaagent-bootstrap's Caffeine patch, we need to compile against our cache API
- // but make sure to run against javaagent-bootstrap
- testCompileOnly(project(":instrumentation-api-caching"))
- testRuntimeOnly(project(":javaagent-bootstrap"))
-
- testImplementation("org.assertj:assertj-core")
-}

MODIFY
javaagent-bootstrap/build.gradle.kts
javaagent-bootstrap/build.gradle.kts
@@ -5,18 +5,6 @@ plugins {
group = "io.opentelemetry.javaagent"
-// patch inner class from Caffeine to avoid ForkJoinTask from being loaded too early
-val patch = sourceSets.create("patch")
-patch.java {}
-
-tasks {
- named<Jar>("jar") {
- from(patch.output) {
- include("io/opentelemetry/instrumentation/api/internal/shaded/caffeine/cache/BoundedLocalCache\$PerformCleanupTask.class")
- }
- }
-}
-
dependencies {
api("io.opentelemetry:opentelemetry-api")
api("io.opentelemetry:opentelemetry-api-metrics")

MODIFY
settings.gradle.kts
settings.gradle.kts
@@ -53,7 +53,6 @@ rootProject.name = "opentelemetry-java-instrumentation"
include(":opentelemetry-api-shaded-for-instrumenting")
include(":opentelemetry-ext-annotations-shaded-for-instrumenting")
include(":javaagent-bootstrap")
-include(":javaagent-bootstrap-tests")
include(":javaagent-exporters")
include(":javaagent-extension-api")
include(":javaagent-tooling")

Move caffeine patching to instrumentation-api-caching (#3559)