Skip to content

Commit 3cc39c8

Browse files
committed
fix(build): Properly wire the unpackJars task
The `unpackJars` task dependency do not have to be declared as a dependency of the compile task, however it should be declared as an included input of the build time instrumentation. Also, the `unpackJars` is now a `Sync` task to deletes files that are no longer in the source JARs.
1 parent dcd1f67 commit 3cc39c8

1 file changed

Lines changed: 18 additions & 27 deletions

File tree

dd-java-agent/agent-otel/otel-bootstrap/build.gradle

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ def otelInstrumentationApiVersion = '2.4.0'
1010
apply from: "$rootDir/gradle/java.gradle"
1111
apply plugin: 'dd-trace-java.build-time-instrumentation'
1212

13-
def otelUnpackedDir = layout.buildDirectory.dir("otel-unpacked")
14-
1513
configurations {
1614
def ec = register('embeddedClasspath') {
1715
visible = false
@@ -30,9 +28,26 @@ configurations {
3028
}
3129
}
3230

31+
// Unpack the embeddedClasspath jars into otelUnpackedDir so that OtelShimGradlePlugin can
32+
// instrument them (e.g. inject the OTel shim).
33+
def unpackOtelJars = tasks.register('unpackOtelJars', Sync) {
34+
exclude 'META-INF/'
35+
exclude '**/module-info.class'
36+
exclude '**/package-info.class'
37+
38+
from(configurations.named('embeddedClasspath').map {
39+
it.collect {
40+
zipTree(it)
41+
}
42+
})
43+
// Note: they are intentionally kept in a separate directory from compileJava's output so that
44+
// Gradle's stale-output cleanup on a full rebuild does not delete them before instrumentation.
45+
into layout.buildDirectory.dir("otel-unpacked")
46+
}
47+
3348
buildTimeInstrumentation {
3449
plugins.addAll('datadog.opentelemetry.tooling.shim.OtelShimGradlePlugin')
35-
includeClassDirectories.from(otelUnpackedDir)
50+
includeClassDirectories.from(unpackOtelJars)
3651
}
3752

3853
minimumInstructionCoverage = 0.0
@@ -59,30 +74,6 @@ dependencies {
5974

6075
compileOnly project(':dd-java-agent:agent-bootstrap')
6176
implementation project(':dd-java-agent:agent-otel:otel-shim')
62-
63-
// buildTimeInstrumentationPlugin project(path: ':dd-java-agent:agent-otel:otel-tooling', configuration: 'buildTimeInstrumentationToolingPlugins')
64-
}
65-
66-
// Unpack the embeddedClasspath jars into otelUnpackedDir so that OtelShimGradlePlugin can
67-
// instrument them (e.g. inject the OTel shim).
68-
tasks.register('unpackOtelJars', Copy) {
69-
dependsOn configurations.named('embeddedClasspath')
70-
exclude 'META-INF/'
71-
exclude '**/module-info.class'
72-
exclude '**/package-info.class'
73-
74-
from(configurations.named('embeddedClasspath').map {
75-
it.collect {
76-
zipTree(it)
77-
}
78-
})
79-
// Note: they are intentionally kept in a separate directory from compileJava's output so that
80-
// Gradle's stale-output cleanup on a full rebuild does not delete them before instrumentation.
81-
into otelUnpackedDir
82-
}
83-
84-
tasks.named('compileJava') {
85-
dependsOn 'unpackOtelJars'
8677
}
8778

8879
tasks.named("shadowJar", ShadowJar) {

0 commit comments

Comments
 (0)