Skip to content

Commit b848caf

Browse files
Improve cacheability of agent shadowJar task (#11878)
feat(agent): Improve cacheability of shadowJar task fix(agent): Address PR feedback feat(build): Improve cacheability of shadowJar task Co-authored-by: bruce.bujon <bruce.bujon@datadoghq.com>
1 parent bee92a4 commit b848caf

2 files changed

Lines changed: 25 additions & 20 deletions

File tree

buildSrc/call-site-instrumentation-plugin/build.gradle.kts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import com.github.jengelman.gradle.plugins.shadow.transformers.ApacheLicenseResourceTransformer
2+
import com.github.jengelman.gradle.plugins.shadow.transformers.ApacheNoticeResourceTransformer
3+
import org.gradle.api.file.DuplicatesStrategy.INCLUDE
4+
15
plugins {
26
java
37
id("com.diffplug.spotless") version "8.4.0"
@@ -69,11 +73,11 @@ tasks {
6973
}
7074

7175
shadowJar {
72-
duplicatesStrategy = DuplicatesStrategy.FAIL
73-
// Let's skip license/notice since this jar's only use is during build
74-
filesMatching(listOf("META-INF/LICENSE*", "META-INF/NOTICE*")) {
75-
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
76-
}
76+
duplicatesStrategy = INCLUDE
77+
transform<ApacheLicenseResourceTransformer>()
78+
transform<ApacheNoticeResourceTransformer>()
79+
failOnDuplicateEntries = true
80+
7781
manifest {
7882
attributes(mapOf("Main-Class" to "datadog.trace.plugin.csi.PluginApplication"))
7983
}

dd-java-agent/build.gradle

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import static org.gradle.api.file.DuplicatesStrategy.INCLUDE
2+
13
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
4+
import com.github.jengelman.gradle.plugins.shadow.transformers.PreserveFirstFoundResourceTransformer
25
import java.util.concurrent.atomic.AtomicBoolean
36
import java.util.jar.JarFile
47

@@ -83,21 +86,19 @@ def generalShadowJarConfig(ShadowJar shadowJarTask) {
8386
mergeServiceFiles()
8487
addMultiReleaseAttribute = false
8588

86-
duplicatesStrategy = DuplicatesStrategy.FAIL
87-
// Service descriptors are intentionally merged by mergeServiceFiles(); let
88-
// duplicate service entries reach that transformer instead of failing first.
89-
filesMatching('META-INF/services/**') {
90-
duplicatesStrategy = DuplicatesStrategy.INCLUDE
91-
}
92-
// Vendored dependencies often repeat license/notice metadata. Keep one copy
93-
// while still failing on unexpected duplicate runtime resources and classes.
94-
filesMatching([
95-
'META-INF/LICENSE*',
96-
'META-INF/NOTICE*',
97-
'META-INF/AL2.0',
98-
'META-INF/LGPL2.1',
99-
]) {
100-
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
89+
// Allow duplicate to merge service files
90+
duplicatesStrategy = INCLUDE
91+
// Ensure there is no duplicate in the final jar after resource transformer applied
92+
failOnDuplicateEntries = true
93+
94+
// Vendored dependencies repeat license/notice metadata; keep a single copy
95+
transform(PreserveFirstFoundResourceTransformer) {
96+
it.include(
97+
'META-INF/LICENSE*',
98+
'META-INF/NOTICE*',
99+
'META-INF/AL2.0',
100+
'META-INF/LGPL2.1',
101+
)
101102
}
102103

103104
// Remove some cruft from the final jar.

0 commit comments

Comments
 (0)