@@ -17,12 +17,21 @@ configurations {
1717 traceShadowInclude
1818}
1919
20+ def includedAgentDir = project. layout. buildDirectory. dir(" generated/included" )
21+ def includedJarFileTree = fileTree(includedAgentDir)
22+
23+ tasks. named(" processResources" ) {
24+ dependsOn(includedJarFileTree)
25+ }
26+
2027// The special pre-check should be compiled with Java 6 to detect unsupported Java versions
2128// and prevent issues for users that still using them.
2229sourceSets {
2330 " main_java6" {
2431 java. srcDirs " ${ project.projectDir} /src/main/java6"
32+
2533 }
34+ main. resources. srcDir(includedAgentDir)
2635}
2736
2837def java6CompileTask = tasks. named(" compileMain_java6Java" ) {
@@ -52,9 +61,6 @@ def generalShadowJarConfig(ShadowJar shadowJarTask) {
5261
5362 duplicatesStrategy = DuplicatesStrategy . FAIL
5463
55- // Include AgentPreCheck compiled with Java 6.
56- from sourceSets. main_java6. output
57-
5864 // Remove some cruft from the final jar.
5965 // These patterns should NOT include **/META-INF/maven/**/pom.properties, which is
6066 // used to report our own dependencies, but we should remove the top-level metadata
@@ -114,29 +120,32 @@ def generalShadowJarConfig(ShadowJar shadowJarTask) {
114120 }
115121}
116122
117- def includeShadowJar (TaskProvider<ShadowJar > includedShadowJarTask , String destinationDir ) {
118- def opentracingFound = new AtomicBoolean ()
119- project. tasks. named(" processResources" , ProcessResources ) {
120- doFirst {
123+ def includeShadowJar (TaskProvider<ShadowJar > includedShadowJarTask , String agentDir , FileTree includedJarFileTree ) {
124+ def expandTask = project. tasks. register(" expandAgentShadowJar${ agentDir.capitalize()} " , Sync ) {
125+ it. group = LifecycleBasePlugin . BUILD_GROUP
126+ it. description = " Expand the included shadow jar into the agent jar under ${ agentDir} "
127+
128+ def opentracingFound = new AtomicBoolean ()
129+ it. doFirst(" detect-open-tracing" ) {
121130 eachFile {
122131 // We seem unlikely to use this name somewhere else.
123132 if (it. path. contains(" opentracing" ) && it. name. contains(" Format\$ Builtin" )) {
124133 opentracingFound. set(true )
125134 }
126135 }
127136 }
128- doLast {
137+ it . doLast( " fail-on-detected-opentracing " ) {
129138 if (opentracingFound. get()) {
130139 throw new GradleException (" OpenTracing direct dependency found!" )
131140 }
132141 }
133142
134- from(zipTree(includedShadowJarTask . map { it . archiveFile })) {
135- into destinationDir
143+ it . into providers . provider { new File (includedJarFileTree . dir, agentDir) }
144+ it . from(zipTree(includedShadowJarTask . map { it . archiveFile })) {
136145 rename ' (^.*)\\ .class$' , ' $1.classdata'
137146 // Rename LICENSE file since it clashes with license dir on non-case sensitive FSs (i.e. Mac)
138147 rename ' ^LICENSE$' , ' LICENSE.renamed'
139- if (destinationDir == ' inst' ) {
148+ if (agentDir == ' inst' ) {
140149 // byte-buddy now ships classes optimized for Java8+ under META-INF/versions/9
141150 // since we target Java8+ we can promote these classes over the pre-Java8 ones
142151 duplicatesStrategy = DuplicatesStrategy . EXCLUDE
@@ -148,39 +157,41 @@ def includeShadowJar(TaskProvider<ShadowJar> includedShadowJarTask, String desti
148157 }
149158 }
150159
151- dependsOn includedShadowJarTask
160+ it . dependsOn includedShadowJarTask
152161 }
153162
163+ includedJarFileTree. builtBy(expandTask)
164+
154165 includedShadowJarTask. configure {
155166 generalShadowJarConfig(it as ShadowJar )
156167 }
157168}
158169
159- def includeSubprojShadowJar (Project includedProjectJar , String destinationDir ) {
170+ def includeSubprojShadowJar (Project includedProjectJar , String destinationDir , FileTree includedJarFileTree ) {
160171 evaluationDependsOn(includedProjectJar. path)
161- includeShadowJar(includedProjectJar. tasks. named(" shadowJar" , ShadowJar ), destinationDir)
172+ includeShadowJar(includedProjectJar. tasks. named(" shadowJar" , ShadowJar ), destinationDir, includedJarFileTree )
162173}
163174
164- includeSubprojShadowJar(project(' :dd-java-agent:instrumentation' ), ' inst' )
165- includeSubprojShadowJar(project(' :dd-java-agent:agent-jmxfetch' ), ' metrics' )
166- includeSubprojShadowJar(project(' :dd-java-agent:agent-profiling' ), ' profiling' )
167- includeSubprojShadowJar(project(' :dd-java-agent:appsec' ), ' appsec' )
168- includeSubprojShadowJar(project(' :dd-java-agent:agent-aiguard' ), ' aiguard' )
169- includeSubprojShadowJar(project(' :dd-java-agent:agent-iast' ), ' iast' )
170- includeSubprojShadowJar(project(' :dd-java-agent:agent-debugger' ), ' debugger' )
171- includeSubprojShadowJar(project(' :dd-java-agent:agent-ci-visibility' ), ' ci-visibility' )
172- includeSubprojShadowJar(project(' :dd-java-agent:agent-llmobs' ), ' llm-obs' )
173- includeSubprojShadowJar(project(' :dd-java-agent:agent-logs-intake' ), ' logs-intake' )
174- includeSubprojShadowJar(project(' :dd-java-agent:cws-tls' ), ' cws-tls' )
175+ includeSubprojShadowJar(project(' :dd-java-agent:instrumentation' ), ' inst' , includedJarFileTree )
176+ includeSubprojShadowJar(project(' :dd-java-agent:agent-jmxfetch' ), ' metrics' , includedJarFileTree )
177+ includeSubprojShadowJar(project(' :dd-java-agent:agent-profiling' ), ' profiling' , includedJarFileTree )
178+ includeSubprojShadowJar(project(' :dd-java-agent:appsec' ), ' appsec' , includedJarFileTree )
179+ includeSubprojShadowJar(project(' :dd-java-agent:agent-aiguard' ), ' aiguard' , includedJarFileTree )
180+ includeSubprojShadowJar(project(' :dd-java-agent:agent-iast' ), ' iast' , includedJarFileTree )
181+ includeSubprojShadowJar(project(' :dd-java-agent:agent-debugger' ), ' debugger' , includedJarFileTree )
182+ includeSubprojShadowJar(project(' :dd-java-agent:agent-ci-visibility' ), ' ci-visibility' , includedJarFileTree )
183+ includeSubprojShadowJar(project(' :dd-java-agent:agent-llmobs' ), ' llm-obs' , includedJarFileTree )
184+ includeSubprojShadowJar(project(' :dd-java-agent:agent-logs-intake' ), ' logs-intake' , includedJarFileTree )
185+ includeSubprojShadowJar(project(' :dd-java-agent:cws-tls' ), ' cws-tls' , includedJarFileTree )
175186
176187def sharedShadowJar = tasks. register(' sharedShadowJar' , ShadowJar ) {
177- configurations = [project. configurations. sharedShadowInclude]
188+ it . configurations = [project. configurations. sharedShadowInclude]
178189 // Put the jar in a different directory so we don't overwrite the normal shadow jar and
179190 // break caching, and also to not interfere with CI scripts that copy everything in the
180191 // libs directory
181192 it. destinationDirectory. set(project. layout. buildDirectory. dir(" shared-lib" ))
182193 // Add a classifier so we don't confuse the jar file with the normal shadow jar
183- archiveClassifier = ' shared'
194+ it . archiveClassifier = ' shared'
184195 it. dependencies {
185196 exclude(project(' :dd-java-agent:agent-bootstrap' ))
186197 exclude(project(' :dd-java-agent:agent-logging' ))
@@ -192,18 +203,21 @@ def sharedShadowJar = tasks.register('sharedShadowJar', ShadowJar) {
192203 exclude(dependency(' org.slf4j::' ))
193204 }
194205}
195- includeShadowJar(sharedShadowJar, ' shared' )
206+ includeShadowJar(sharedShadowJar, ' shared' , includedJarFileTree )
196207
197208// place the tracer in its own shadow jar separate to instrumentation
198209def traceShadowJar = tasks. register(' traceShadowJar' , ShadowJar ) {
199- configurations = [project. configurations. traceShadowInclude]
210+ it . configurations = [project. configurations. traceShadowInclude]
200211 it. destinationDirectory. set(project. layout. buildDirectory. dir(" trace-lib" ))
201- archiveClassifier = ' trace'
212+ it . archiveClassifier = ' trace'
202213 it. dependencies deps. excludeShared
203214}
204- includeShadowJar(traceShadowJar, ' trace' )
215+ includeShadowJar(traceShadowJar, ' trace' , includedJarFileTree )
205216
206217tasks. named(" shadowJar" , ShadowJar ) {
218+ // Include AgentPreCheck compiled with Java 6.
219+ from sourceSets. main_java6. output
220+
207221 generalShadowJarConfig(it)
208222
209223 configurations = [project. configurations. shadowInclude]
@@ -221,24 +235,35 @@ tasks.named("shadowJar", ShadowJar) {
221235 }
222236}
223237
224- tasks. register(' generateAgentJarIndex' , JavaExec ) {
225- def indexName = ' dd-java-agent.index'
226- def contentDir = " ${ sourceSets.main.output.resourcesDir} "
227- def indexFile = " ${ contentDir} /${ indexName} "
238+ // temporary config to add slf4j-simple so we get logging while indexing
239+ project. configurations. register(' slf4j-simple' ) {
240+ it. dependencies. add(project. dependencyFactory. create(" org.slf4j:slf4j-simple:${ libs.versions.slf4j.get()} " ))
241+ }
242+
243+ def generateAgentJarIndex = tasks. register(' generateAgentJarIndex' , JavaExec ) {
244+ def destinationDir = project. layout. buildDirectory. dir(" generated/${ it.name} " )
228245
229- it. group = ' Build '
246+ it. group = LifecycleBasePlugin . BUILD_GROUP
230247 it. description = " Generate dd-java-agent.index"
231- it. inputs. files(fileTree(contentDir). exclude(indexName))
232- it. outputs. files(indexFile)
233248 it. mainClass = ' datadog.trace.bootstrap.AgentJarIndex$IndexGenerator'
234- it. classpath = project. configurations. shadowInclude
235- it. args = [contentDir]
236249
237- dependsOn ' processResources'
238- dependsOn ' writeVersionNumberFile'
250+ it. inputs. files(includedJarFileTree)
251+ it. inputs. files(it. classpath)
252+ it. outputs. dir(destinationDir)
253+ it. classpath = objects. fileCollection(). tap {
254+ it. from(project. configurations. named(" shadowInclude" ))
255+ it. from(project. configurations. named(' slf4j-simple' ))
256+ }
257+ // debuggable within gradle using:
258+ // it.jvmArgs("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")
259+ it. argumentProviders. add(new CommandLineArgumentProvider () {
260+ @Override
261+ Iterable<String > asArguments () {
262+ return [includedAgentDir. get(). asFile. path, destinationDir. get(). asFile. path,]
263+ }
264+ })
239265}
240-
241- compileJava. dependsOn ' generateAgentJarIndex'
266+ sourceSets. main. resources. srcDir(generateAgentJarIndex)
242267
243268subprojects { Project subProj ->
244269 // Don't need javadoc task run for internal projects.
0 commit comments