Skip to content

Commit e3373b6

Browse files
authored
Method includeShadowJar was breaking shadowJar tasks laziness (#9626)
1 parent 9449786 commit e3373b6

File tree

15 files changed

+141
-102
lines changed

15 files changed

+141
-102
lines changed

dd-java-agent/agent-ci-visibility/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
13
buildscript {
24
repositories {
35
mavenLocal()
@@ -57,7 +59,7 @@ dependencies {
5759
testImplementation group: 'org.msgpack', name: 'jackson-dataformat-msgpack', version: '0.9.6'
5860
}
5961

60-
shadowJar {
62+
tasks.named("shadowJar", ShadowJar) {
6163
dependencies deps.excludeShared
6264
}
6365

dd-java-agent/agent-debugger/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
13
plugins {
24
id 'com.gradleup.shadow'
35
}
@@ -62,7 +64,7 @@ dependencies {
6264
testRuntimeOnly group: 'antlr', name: 'antlr', version: '2.7.7'
6365
}
6466

65-
shadowJar {
67+
tasks.named("shadowJar", ShadowJar) {
6668
dependencies deps.excludeShared
6769
dependencies {
6870
exclude(project(':dd-java-agent:agent-debugger:debugger-bootstrap'))

dd-java-agent/agent-iast/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
12
import net.ltgt.gradle.errorprone.CheckSeverity
23

34
plugins {
@@ -74,7 +75,7 @@ dependencies {
7475
errorprone('com.google.errorprone:error_prone_core:2.23.0')
7576
}
7677

77-
shadowJar {
78+
tasks.named("shadowJar", ShadowJar) {
7879
dependencies deps.excludeShared
7980
}
8081

dd-java-agent/agent-jmxfetch/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
13
import java.nio.file.Files
24
import java.nio.file.attribute.BasicFileAttributes
35
import java.util.stream.Collectors
@@ -23,7 +25,7 @@ dependencies {
2325
api project(':dd-java-agent:agent-bootstrap')
2426
}
2527

26-
shadowJar {
28+
tasks.named("shadowJar", ShadowJar) {
2729
dependencies deps.excludeShared
2830
}
2931

dd-java-agent/agent-llmobs/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
13
buildscript {
24
repositories {
35
mavenCentral()
@@ -30,7 +32,7 @@ dependencies {
3032
testImplementation project(':dd-java-agent:testing')
3133
}
3234

33-
shadowJar {
35+
tasks.named("shadowJar", ShadowJar) {
3436
dependencies deps.excludeShared
3537
}
3638

dd-java-agent/agent-logs-intake/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
13
plugins {
24
id 'com.gradleup.shadow'
35
}
@@ -15,7 +17,7 @@ dependencies {
1517
implementation project(':communication')
1618
}
1719

18-
shadowJar {
20+
tasks.named("shadowJar", ShadowJar) {
1921
dependencies deps.excludeShared
2022
}
2123

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
13
plugins {
24
id 'com.gradleup.shadow'
35
}
@@ -65,7 +67,7 @@ tasks.named('compileJava') {
6567
dependsOn 'unpackJars'
6668
}
6769

68-
shadowJar {
70+
tasks.named("shadowJar", ShadowJar) {
6971
dependencies deps.excludeShared
7072

7173
include '*.jar'

dd-java-agent/agent-profiling/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
13
plugins {
24
id 'com.gradleup.shadow'
35
}
@@ -38,7 +40,7 @@ configurations {
3840
}
3941
}
4042

41-
shadowJar {
43+
tasks.named("shadowJar", ShadowJar) {
4244
dependencies deps.excludeShared
4345
}
4446

dd-java-agent/appsec/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
12
import groovy.json.JsonOutput
23
import groovy.json.JsonSlurper
34

@@ -25,7 +26,7 @@ dependencies {
2526
testImplementation libs.jackson.databind
2627
}
2728

28-
shadowJar {
29+
tasks.named("shadowJar", ShadowJar) {
2930
exclude '**/*-dbgsym.zip'
3031
dependencies deps.excludeShared
3132
}

dd-java-agent/build.gradle

Lines changed: 90 additions & 84 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 destinationDir) {
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 destinationDir
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 (destinationDir == '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,29 @@ 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

156-
def includeSubprojShadowJar(String projName, String jarname) {
157-
evaluationDependsOn projName
158-
def proj = project(projName)
159-
includeShadowJar proj.tasks.named("shadowJar"), jarname
161+
def includeSubprojShadowJar(Project includedProjectJar, String destinationDir) {
162+
evaluationDependsOn(includedProjectJar.path)
163+
includeShadowJar(includedProjectJar.tasks.named("shadowJar", ShadowJar), destinationDir)
160164
}
161165

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'
166+
includeSubprojShadowJar(project(':dd-java-agent:instrumentation'), 'inst')
167+
includeSubprojShadowJar(project(':dd-java-agent:agent-jmxfetch'), 'metrics')
168+
includeSubprojShadowJar(project(':dd-java-agent:agent-profiling'), 'profiling')
169+
includeSubprojShadowJar(project(':dd-java-agent:appsec'), 'appsec')
170+
includeSubprojShadowJar(project(':dd-java-agent:agent-iast'), 'iast')
171+
includeSubprojShadowJar(project(':dd-java-agent:agent-debugger'), 'debugger')
172+
includeSubprojShadowJar(project(':dd-java-agent:agent-ci-visibility'), 'ci-visibility')
173+
includeSubprojShadowJar(project(':dd-java-agent:agent-llmobs'), 'llm-obs')
174+
includeSubprojShadowJar(project(':dd-java-agent:agent-logs-intake'), 'logs-intake')
175+
includeSubprojShadowJar(project(':dd-java-agent:cws-tls'), 'cws-tls')
172176

173177
def sharedShadowJar = tasks.register('sharedShadowJar', ShadowJar) {
174178
configurations = [project.configurations.sharedShadowInclude]
@@ -200,7 +204,9 @@ def traceShadowJar = tasks.register('traceShadowJar', ShadowJar) {
200204
}
201205
includeShadowJar(traceShadowJar, 'trace')
202206

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

206212
archiveClassifier = ''
@@ -352,7 +358,7 @@ tasks.register('checkAgentJarSize') {
352358
doLast {
353359
// Arbitrary limit to prevent unintentional increases to the agent jar size
354360
// Raise or lower as required
355-
assert shadowJar.archiveFile.get().getAsFile().length() <= 32 * 1024 * 1024
361+
assert tasks.named("shadowJar", ShadowJar).get().archiveFile.get().getAsFile().length() <= 32 * 1024 * 1024
356362
}
357363

358364
dependsOn "shadowJar"

0 commit comments

Comments
 (0)