Skip to content

Commit 4f2fc6a

Browse files
committed
fix: includeShadowJar was breaking shadowJar tasks laziness
1 parent 4cf7670 commit 4f2fc6a

File tree

1 file changed

+88
-81
lines changed

1 file changed

+88
-81
lines changed

dd-java-agent/build.gradle

Lines changed: 88 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -46,73 +46,75 @@ dependencies {
4646
* This general config is shared by all of them
4747
*/
4848

49-
ext.generalShadowJarConfig = {
50-
mergeServiceFiles()
51-
52-
duplicatesStrategy = DuplicatesStrategy.FAIL
53-
54-
// Include AgentPreCheck compiled with Java 6.
55-
from sourceSets.main_java6.output
56-
57-
// Remove some cruft from the final jar.
58-
// These patterns should NOT include **/META-INF/maven/**/pom.properties, which is
59-
// used to report our own dependencies, but we should remove the top-level metadata
60-
// of vendored packages because those could trigger unwanted framework checks.
61-
exclude '/META-INF/maven/org.slf4j/**'
62-
exclude '/META-INF/maven/org.snakeyaml/**'
63-
exclude '**/META-INF/maven/**/pom.xml'
64-
exclude '**/META-INF/proguard/'
65-
exclude '**/META-INF/*.kotlin_module'
66-
exclude '**/module-info.class'
67-
exclude '**/liblz4-java.so'
68-
exclude '**/liblz4-java.dylib'
69-
exclude '**/inst/META-INF/versions/**'
70-
exclude '**/META-INF/versions/*/org/yaml/**'
71-
72-
// Replaced by 'instrumenter.index', no need to include original service file
73-
exclude '**/META-INF/services/datadog.trace.agent.tooling.InstrumenterModule'
74-
75-
// Prevents conflict with other SLF4J instances. Important for premain.
76-
relocate 'org.slf4j', 'datadog.slf4j'
77-
// Prevent conflicts with flat class-path when using GraalVM native-images
78-
relocate 'org.jctools', 'datadog.jctools'
79-
relocate 'net.jpountz', 'datadog.jpountz'
80-
// rewrite dependencies calling Logger.getLogger
81-
relocate 'java.util.logging.Logger', 'datadog.trace.bootstrap.PatchLogger'
82-
// patch JFFI loading mechanism to maintain isolation
83-
exclude '**/com/kenai/jffi/Init.class'
84-
relocate('com.kenai.jffi.Init', 'com.kenai.jffi.PatchInit')
85-
86-
// Minimize and relocate the airlift compressor dependency for ZSTD
87-
exclude '**/io/airlift/compress/bzip2/**'
88-
exclude '**/io/airlift/compress/deflate/**'
89-
exclude '**/io/airlift/compress/gzip/**'
90-
exclude '**/io/airlift/compress/hadoop/**'
91-
exclude '**/io/airlift/compress/lz4/**'
92-
exclude '**/io/airlift/compress/lzo/**'
93-
exclude '**/io/airlift/compress/snappy/**'
94-
relocate 'io.airlift', 'datadog.io.airlift'
95-
96-
final String projectName = "${project.name}"
97-
98-
// Prevents conflict with other instances, but doesn't relocate instrumentation
99-
if (!projectName.equals('instrumentation')) {
100-
relocate 'org.snakeyaml.engine', 'datadog.snakeyaml.engine'
101-
relocate 'okhttp3', 'datadog.okhttp3'
102-
relocate 'okio', 'datadog.okio'
103-
}
49+
def generalShadowJarConfig(ShadowJar shadowJarTask) {
50+
shadowJarTask.with {
51+
mergeServiceFiles()
52+
53+
duplicatesStrategy = DuplicatesStrategy.FAIL
54+
55+
// Include AgentPreCheck compiled with Java 6.
56+
from sourceSets.main_java6.output
57+
58+
// Remove some cruft from the final jar.
59+
// These patterns should NOT include **/META-INF/maven/**/pom.properties, which is
60+
// used to report our own dependencies, but we should remove the top-level metadata
61+
// of vendored packages because those could trigger unwanted framework checks.
62+
exclude '/META-INF/maven/org.slf4j/**'
63+
exclude '/META-INF/maven/org.snakeyaml/**'
64+
exclude '**/META-INF/maven/**/pom.xml'
65+
exclude '**/META-INF/proguard/'
66+
exclude '**/META-INF/*.kotlin_module'
67+
exclude '**/module-info.class'
68+
exclude '**/liblz4-java.so'
69+
exclude '**/liblz4-java.dylib'
70+
exclude '**/inst/META-INF/versions/**'
71+
exclude '**/META-INF/versions/*/org/yaml/**'
72+
73+
// Replaced by 'instrumenter.index', no need to include original service file
74+
exclude '**/META-INF/services/datadog.trace.agent.tooling.InstrumenterModule'
75+
76+
// Prevents conflict with other SLF4J instances. Important for premain.
77+
relocate 'org.slf4j', 'datadog.slf4j'
78+
// Prevent conflicts with flat class-path when using GraalVM native-images
79+
relocate 'org.jctools', 'datadog.jctools'
80+
relocate 'net.jpountz', 'datadog.jpountz'
81+
// rewrite dependencies calling Logger.getLogger
82+
relocate 'java.util.logging.Logger', 'datadog.trace.bootstrap.PatchLogger'
83+
// patch JFFI loading mechanism to maintain isolation
84+
exclude '**/com/kenai/jffi/Init.class'
85+
relocate('com.kenai.jffi.Init', 'com.kenai.jffi.PatchInit')
86+
87+
// Minimize and relocate the airlift compressor dependency for ZSTD
88+
exclude '**/io/airlift/compress/bzip2/**'
89+
exclude '**/io/airlift/compress/deflate/**'
90+
exclude '**/io/airlift/compress/gzip/**'
91+
exclude '**/io/airlift/compress/hadoop/**'
92+
exclude '**/io/airlift/compress/lz4/**'
93+
exclude '**/io/airlift/compress/lzo/**'
94+
exclude '**/io/airlift/compress/snappy/**'
95+
relocate 'io.airlift', 'datadog.io.airlift'
96+
97+
final String projectName = "${project.name}"
98+
99+
// Prevents conflict with other instances, but doesn't relocate instrumentation
100+
if (!projectName.equals('instrumentation')) {
101+
relocate 'org.snakeyaml.engine', 'datadog.snakeyaml.engine'
102+
relocate 'okhttp3', 'datadog.okhttp3'
103+
relocate 'okio', 'datadog.okio'
104+
}
104105

105-
if (!project.hasProperty("disableShadowRelocate") || !disableShadowRelocate) {
106-
// shadow OT impl to prevent casts to implementation
107-
relocate 'datadog.trace.common', 'datadog.trace.agent.common'
108-
relocate 'datadog.trace.core', 'datadog.trace.agent.core'
109-
relocate 'datadog.opentracing', 'datadog.trace.agent.ot'
110-
// shadow things in internal API that has slf4j in the API and is accessed from core
111-
relocate 'datadog.trace.relocate', 'datadog.trace.agent.relocate'
106+
if (!project.hasProperty("disableShadowRelocate") || !disableShadowRelocate) {
107+
// shadow OT impl to prevent casts to implementation
108+
relocate 'datadog.trace.common', 'datadog.trace.agent.common'
109+
relocate 'datadog.trace.core', 'datadog.trace.agent.core'
110+
relocate 'datadog.opentracing', 'datadog.trace.agent.ot'
111+
// shadow things in internal API that has slf4j in the API and is accessed from core
112+
relocate 'datadog.trace.relocate', 'datadog.trace.agent.relocate'
113+
}
112114
}
113115
}
114116

115-
def includeShadowJar(TaskProvider<ShadowJar> shadowJarTask, String jarname) {
117+
def includeShadowJar(TaskProvider<ShadowJar> includedShadowJarTask, String dirLocation) {
116118
def opentracingFound = new AtomicBoolean()
117119
project.processResources {
118120
doFirst {
@@ -129,12 +131,12 @@ def includeShadowJar(TaskProvider<ShadowJar> shadowJarTask, String jarname) {
129131
}
130132
}
131133

132-
from(zipTree(shadowJarTask.get().archiveFile)) {
133-
into jarname
134+
from(zipTree(includedShadowJarTask.map { it.archiveFile })) {
135+
into dirLocation
134136
rename '(^.*)\\.class$', '$1.classdata'
135137
// Rename LICENSE file since it clashes with license dir on non-case sensitive FSs (i.e. Mac)
136138
rename '^LICENSE$', 'LICENSE.renamed'
137-
if (jarname == 'inst') {
139+
if (dirLocation == 'inst') {
138140
// byte-buddy now ships classes optimized for Java8+ under META-INF/versions/9
139141
// since we target Java8+ we can promote these classes over the pre-Java8 ones
140142
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
@@ -148,27 +150,30 @@ def includeShadowJar(TaskProvider<ShadowJar> shadowJarTask, String jarname) {
148150
}
149151

150152
project.tasks.named("processResources") {
151-
dependsOn shadowJarTask
153+
dependsOn includedShadowJarTask
154+
}
155+
156+
includedShadowJarTask.configure {
157+
generalShadowJarConfig(it as ShadowJar)
152158
}
153-
shadowJarTask.configure generalShadowJarConfig
154159
}
155160

156161
def includeSubprojShadowJar(String projName, String jarname) {
157162
evaluationDependsOn projName
158163
def proj = project(projName)
159-
includeShadowJar proj.tasks.named("shadowJar"), jarname
164+
includeShadowJar(proj.tasks.named("shadowJar", ShadowJar), jarname)
160165
}
161166

162-
includeSubprojShadowJar ':dd-java-agent:instrumentation', 'inst'
163-
includeSubprojShadowJar ':dd-java-agent:agent-jmxfetch', 'metrics'
164-
includeSubprojShadowJar ':dd-java-agent:agent-profiling', 'profiling'
165-
includeSubprojShadowJar ':dd-java-agent:appsec', 'appsec'
166-
includeSubprojShadowJar ':dd-java-agent:agent-iast', 'iast'
167-
includeSubprojShadowJar ':dd-java-agent:agent-debugger', 'debugger'
168-
includeSubprojShadowJar ':dd-java-agent:agent-ci-visibility', 'ci-visibility'
169-
includeSubprojShadowJar ':dd-java-agent:agent-llmobs', 'llm-obs'
170-
includeSubprojShadowJar ':dd-java-agent:agent-logs-intake', 'logs-intake'
171-
includeSubprojShadowJar ':dd-java-agent:cws-tls', 'cws-tls'
167+
includeSubprojShadowJar(':dd-java-agent:instrumentation', 'inst')
168+
includeSubprojShadowJar(':dd-java-agent:agent-jmxfetch', 'metrics')
169+
includeSubprojShadowJar(':dd-java-agent:agent-profiling', 'profiling')
170+
includeSubprojShadowJar(':dd-java-agent:appsec', 'appsec')
171+
includeSubprojShadowJar(':dd-java-agent:agent-iast', 'iast')
172+
includeSubprojShadowJar(':dd-java-agent:agent-debugger', 'debugger')
173+
includeSubprojShadowJar(':dd-java-agent:agent-ci-visibility', 'ci-visibility')
174+
includeSubprojShadowJar(':dd-java-agent:agent-llmobs', 'llm-obs')
175+
includeSubprojShadowJar(':dd-java-agent:agent-logs-intake', 'logs-intake')
176+
includeSubprojShadowJar(':dd-java-agent:cws-tls', 'cws-tls')
172177

173178
def sharedShadowJar = tasks.register('sharedShadowJar', ShadowJar) {
174179
configurations = [project.configurations.sharedShadowInclude]
@@ -200,7 +205,9 @@ def traceShadowJar = tasks.register('traceShadowJar', ShadowJar) {
200205
}
201206
includeShadowJar(traceShadowJar, 'trace')
202207

203-
shadowJar generalShadowJarConfig >> {
208+
tasks.named("shadowJar", ShadowJar) {
209+
generalShadowJarConfig(it)
210+
204211
configurations = [project.configurations.shadowInclude]
205212

206213
archiveClassifier = ''
@@ -212,7 +219,7 @@ shadowJar generalShadowJarConfig >> {
212219
"Premain-Class": "datadog.trace.bootstrap.AgentPreCheck",
213220
"Can-Redefine-Classes": true,
214221
"Can-Retransform-Classes": true,
215-
)
222+
)
216223
}
217224
}
218225

0 commit comments

Comments
 (0)