forked from DataDog/dd-trace-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdd-java-agent.gradle
More file actions
204 lines (171 loc) · 6.5 KB
/
dd-java-agent.gradle
File metadata and controls
204 lines (171 loc) · 6.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import java.util.concurrent.atomic.AtomicBoolean
plugins {
id "com.github.johnrengelman.shadow"
}
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'
// 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.trace.core', 'datadog.trace.agent.core'
relocate 'datadog.opentracing', 'datadog.trace.agent.ot'
// shadow things in internal API that has slf4j in the API and is accessed from core
relocate 'datadog.trace.relocate', 'datadog.trace.agent.relocate'
}
}
def includeShadowJar(TaskProvider<ShadowJar> shadowJarTask, String jarname) {
def opentracingFound = new AtomicBoolean()
project.processResources {
doFirst {
eachFile {
// We seem unlikely to use this name somewhere else.
if (it.path.contains("opentracing") && it.name.contains("Format\$Builtin")) {
opentracingFound.set(true)
}
}
}
doLast {
if (opentracingFound.get()) {
throw new GradleException("OpenTracing direct dependency found!")
}
}
from(zipTree(shadowJarTask.get().archiveFile)) {
into jarname
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.tasks.named("processResources").configure {
dependsOn shadowJarTask
}
shadowJarTask.configure generalShadowJarConfig
}
def includeSubprojShadowJar(String projName, String jarname) {
evaluationDependsOn projName
def proj = project(projName)
includeShadowJar proj.tasks.named("shadowJar"), jarname
}
includeSubprojShadowJar ':dd-java-agent:instrumentation', 'inst'
includeSubprojShadowJar ':dd-java-agent:agent-jmxfetch', 'metrics'
includeSubprojShadowJar ':dd-java-agent:agent-profiling', 'profiling'
includeSubprojShadowJar ':dd-java-agent:appsec', 'appsec'
def sharedShadowJar = tasks.register('sharedShadowJar', ShadowJar) {
configurations = [project.configurations.sharedShadowInclude]
// Put the jar in a different directory so we don't overwrite the normal shadow jar and
// break caching, and also to not interfere with CI scripts that copy everything in the
// libs directory
it.destinationDirectory.set(file("${project.buildDir}/shared-lib"))
// Add a classifier so we don't confuse the jar file with the normal shadow jar
archiveClassifier = 'shared'
it.dependencies {
exclude(project(':dd-java-agent:agent-bootstrap'))
exclude(project(':dd-java-agent:agent-logging'))
exclude(project(':dd-trace-api'))
exclude(project(':internal-api'))
exclude(project(':internal-api:internal-api-8'))
exclude(dependency('org.slf4j::'))
}
}
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,
)
}
}
subprojects { Project subProj ->
// Don't need javadoc task run for internal projects.
subProj.tasks.withType(Javadoc).configureEach { enabled = false }
}
// We don't want bundled dependencies to show up in the pom.
tasks.withType(GenerateMavenPom).configureEach { task ->
doFirst {
task.pom.withXml { XmlProvider provider ->
Node dependencies = provider.asNode().dependencies[0]
dependencies.children().clear()
}
}
}
dependencies {
testImplementation(project(':dd-java-agent:agent-bootstrap')) {
exclude group: 'com.datadoghq', module: 'agent-logging'
}
testImplementation project(':dd-trace-api')
testImplementation project(':dd-trace-core')
testImplementation project(':utils:test-utils')
testImplementation deps.testLogging
testImplementation deps.guava
testImplementation deps.okhttp
testImplementation group: 'io.opentracing', name: 'opentracing-util', version: '0.31.0'
// Includes for the top level shadow jar
shadowInclude project(path: ':dd-java-agent:agent-bootstrap')
// Includes for the shared internal shadow jar
sharedShadowInclude project(':utils:socket-utils')
sharedShadowInclude deps.shared
sharedShadowInclude deps.moshi
sharedShadowInclude project(':communication'), {
transitive = false
// do not bring along slf4j and dependent subprojects
// (which are loaded on the bootstrap cl)
}
sharedShadowInclude project(':utils:container-utils'), {
transitive = false
}
}
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"
}
tasks.register('checkAgentJarSize').configure {
doLast {
// Arbitrary limit to prevent unintentional increases to the agent jar size
// Raise or lower as required
assert shadowJar.archiveFile.get().getAsFile().length() < 19 * 1024 * 1024
}
dependsOn "shadowJar"
}
tasks.named('check').configure {
dependsOn 'checkAgentJarSize'
}