135 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			Groovy
		
	
	
	
			
		
		
	
	
			135 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			Groovy
		
	
	
	
| import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
 | |
| 
 | |
| plugins {
 | |
|   id "com.github.johnrengelman.shadow" version "5.2.0"
 | |
| }
 | |
| 
 | |
| description = 'dd-java-agent'
 | |
| 
 | |
| apply from: "${rootDir}/gradle/java.gradle"
 | |
| apply from: "${rootDir}/gradle/publish.gradle"
 | |
| 
 | |
| configurations {
 | |
|   shadowInclude
 | |
|   sharedShadowInclude
 | |
| }
 | |
| 
 | |
| /*
 | |
|  * 4 shadow jars are created
 | |
|  * - The main "dd-java-agent" jar that also has the bootstrap project
 | |
|  * - 2 jars based on projects (jmxfetch, agent tooling)
 | |
|  * - 1 based on the shared dependencies
 | |
|  * This general config is shared by all of them
 | |
|  */
 | |
| 
 | |
| ext.generalShadowJarConfig = {
 | |
|   mergeServiceFiles()
 | |
| 
 | |
|   exclude '**/module-info.class'
 | |
| 
 | |
|   dependencies {
 | |
|     exclude(dependency("org.projectlombok:lombok:$versions.lombok"))
 | |
|   }
 | |
| 
 | |
|   // Prevents conflict with other SLF4J instances. Important for premain.
 | |
|   relocate 'org.slf4j', 'datadog.slf4j'
 | |
|   // rewrite dependencies calling Logger.getLogger
 | |
|   relocate 'java.util.logging.Logger', 'datadog.trace.bootstrap.PatchLogger'
 | |
| 
 | |
|   if (!project.hasProperty("disableShadowRelocate") || !disableShadowRelocate) {
 | |
|     // shadow OT impl to prevent casts to implementation
 | |
|     relocate 'datadog.trace.common', 'datadog.trace.agent.common'
 | |
|     relocate 'datadog.opentracing', 'datadog.trace.agent.ot'
 | |
|   }
 | |
| }
 | |
| 
 | |
| def includeShadowJar(shadowJarTask, jarname) {
 | |
|   project.processResources {
 | |
|     from(zipTree(shadowJarTask.archiveFile)) {
 | |
|       into jarname + '.isolated'
 | |
|       rename '(^.*)\\.class$', '$1.classdata'
 | |
|       // Rename LICENSE file since it clashes with license dir on non-case sensitive FSs (i.e. Mac)
 | |
|       rename '^LICENSE$', 'LICENSE.renamed'
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   project.processResources.dependsOn shadowJarTask
 | |
|   shadowJarTask.configure generalShadowJarConfig
 | |
| }
 | |
| 
 | |
| project(':dd-java-agent:instrumentation').afterEvaluate {
 | |
|   includeShadowJar(it.tasks.shadowJar, 'agent-tooling-and-instrumentation')
 | |
| }
 | |
| project(':dd-java-agent:agent-jmxfetch').afterEvaluate {
 | |
|   includeShadowJar(it.tasks.shadowJar, 'agent-jmxfetch')
 | |
| }
 | |
| project(':dd-java-agent:agent-profiling').afterEvaluate {
 | |
|   includeShadowJar(it.tasks.shadowJar, 'agent-profiling')
 | |
| }
 | |
| 
 | |
| task sharedShadowJar(type: ShadowJar) {
 | |
|   configurations = [project.configurations.sharedShadowInclude]
 | |
| }
 | |
| includeShadowJar(sharedShadowJar, 'shared')
 | |
| 
 | |
| shadowJar generalShadowJarConfig >> {
 | |
|   configurations = [project.configurations.shadowInclude]
 | |
| 
 | |
|   archiveClassifier = ''
 | |
| 
 | |
|   manifest {
 | |
|     attributes(
 | |
|       "Main-Class": "datadog.trace.bootstrap.AgentBootstrap",
 | |
|       "Agent-Class": "datadog.trace.bootstrap.AgentBootstrap",
 | |
|       "Premain-Class": "datadog.trace.bootstrap.AgentBootstrap",
 | |
|       "Can-Redefine-Classes": true,
 | |
|       "Can-Retransform-Classes": true,
 | |
|     )
 | |
|   }
 | |
| }
 | |
| 
 | |
| // We don't want bundled dependencies to show up in the pom.
 | |
| modifyPom {
 | |
|   dependencies.removeAll { true }
 | |
| }
 | |
| 
 | |
| dependencies {
 | |
|   testCompile project(':dd-java-agent:agent-bootstrap')
 | |
|   testCompile project(':dd-trace-api')
 | |
|   testCompile project(':dd-trace-ot')
 | |
|   testCompile project(':utils:test-utils')
 | |
| 
 | |
|   testCompile deps.opentracingMock
 | |
|   testCompile deps.testLogging
 | |
|   testCompile deps.guava
 | |
| 
 | |
|   // Includes for the top level shadow jar
 | |
|   shadowInclude project(path: ':dd-java-agent:agent-bootstrap')
 | |
| 
 | |
|   // Includes for the shared internal shadow jar
 | |
|   sharedShadowInclude deps.shared
 | |
| }
 | |
| 
 | |
| tasks.withType(Test).configureEach {
 | |
|   jvmArgs "-Ddd.service.name=java-agent-tests"
 | |
|   jvmArgs "-Ddd.writer.type=LoggingWriter"
 | |
|   // Multi-threaded logging seems to be causing deadlocks with Gradle's log capture.
 | |
| //  jvmArgs "-Ddatadog.slf4j.simpleLogger.defaultLogLevel=debug"
 | |
| //  jvmArgs "-Dorg.slf4j.simpleLogger.defaultLogLevel=debug"
 | |
| 
 | |
|   doFirst {
 | |
|     // Defining here to allow jacoco to be first on the command line.
 | |
|     jvmArgs "-javaagent:${shadowJar.archivePath}"
 | |
|   }
 | |
| 
 | |
|   testLogging {
 | |
|     events "started"
 | |
|   }
 | |
| 
 | |
|   if (project.hasProperty("disableShadowRelocate") && disableShadowRelocate) {
 | |
|     exclude 'datadog/trace/agent/integration/classloading/ShadowPackageRenamingTest.class'
 | |
|   }
 | |
| 
 | |
|   dependsOn shadowJar
 | |
| }
 |