1
+ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction
1
2
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2
3
import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext
3
4
import org.apache.tools.zip.ZipEntry
@@ -20,12 +21,30 @@ plugins {
20
21
// this configuration collects libs that will be placed in the bootstrap classloader
21
22
val bootstrapLibs: Configuration by configurations.creating {
22
23
isCanBeConsumed = false
24
+ isCanBeResolved = false
23
25
}
24
26
val javaagentLibs: Configuration by configurations.creating {
25
27
isCanBeConsumed = false
28
+ isCanBeResolved = false
26
29
}
27
30
val upstreamAgent: Configuration by configurations.creating {
28
31
isCanBeConsumed = false
32
+ isCanBeResolved = false
33
+ }
34
+ val bootstrapLibsClasspath: Configuration by configurations.creating {
35
+ extendsFrom(bootstrapLibs)
36
+ isCanBeConsumed = false
37
+ isCanBeResolved = true
38
+ }
39
+ val javaagentLibsClasspath: Configuration by configurations.creating {
40
+ extendsFrom(javaagentLibs)
41
+ isCanBeConsumed = false
42
+ isCanBeResolved = true
43
+ }
44
+ val upstreamAgentClasspath: Configuration by configurations.creating {
45
+ extendsFrom(upstreamAgent)
46
+ isCanBeConsumed = false
47
+ isCanBeResolved = true
29
48
}
30
49
31
50
dependencies {
@@ -70,14 +89,15 @@ tasks {
70
89
71
90
// 1. all distro specific javaagent libs are relocated
72
91
val relocateJavaagentLibs = register<ShadowJar >(" relocateJavaagentLibs" ) {
73
- configurations = listOf (javaagentLibs )
92
+ configurations = listOf (javaagentLibsClasspath )
74
93
75
- duplicatesStrategy = DuplicatesStrategy .FAIL
94
+ duplicatesStrategy = DuplicatesStrategy .INCLUDE
95
+ failOnDuplicateEntries = true
76
96
77
97
archiveFileName.set(" javaagentLibs-relocated.jar" )
78
98
79
99
mergeServiceFiles()
80
- exclude(" **/module-info.class" )
100
+ exclude(" **/module-info.class" , " META-INF/LICENSE* " , " META-INF/NOTICE* " )
81
101
relocatePackages(this )
82
102
83
103
// exclude known bootstrap dependencies - they can't appear in the inst/ directory
@@ -116,7 +136,7 @@ tasks {
116
136
// This transformer injects a new Field into the Opentelemetry SdkSpan class to be used
117
137
// as efficient storage for co.elastic.otel.common.SpanValues
118
138
// Check the FieldBackedSpanValueStorageProvider for details
119
- val injectSpanValueFieldTransformer = object : com.github.jengelman.gradle.plugins.shadow.transformers.Transformer {
139
+ val injectSpanValueFieldTransformer = object : com.github.jengelman.gradle.plugins.shadow.transformers.ResourceTransformer {
120
140
121
141
@Internal
122
142
val SDK_SPAN_CLASS_FILE = " inst/io/opentelemetry/sdk/trace/SdkSpan.classdata"
@@ -131,15 +151,15 @@ tasks {
131
151
}
132
152
133
153
override fun canTransformResource (element : FileTreeElement ): Boolean {
134
- return element.name.equals( SDK_SPAN_CLASS_FILE )
154
+ return element.path == SDK_SPAN_CLASS_FILE
135
155
}
136
156
137
157
override fun transform (context : TransformerContext ) {
138
158
if (bytecode != null ) {
139
159
throw IllegalStateException (" Multiple SdkSpan classes detected" )
140
160
}
141
161
142
- val inputStream = context.getIs()
162
+ val inputStream = context.inputStream
143
163
val reader = ClassReader (inputStream)
144
164
val writer = ClassWriter (reader, 0 )
145
165
val visitor = object : ClassVisitor (Opcodes .ASM9 , writer) {
@@ -168,33 +188,38 @@ tasks {
168
188
}
169
189
170
190
val entry = ZipEntry (SDK_SPAN_CLASS_FILE )
171
- entry.time = TransformerContext . getEntryTimestamp(preserveFileTimestamps, entry.time)
191
+ entry.time = getEntryTimestamp(preserveFileTimestamps, entry.time)
172
192
os.putNextEntry(entry)
173
193
os.write(bytecode)
174
194
}
175
195
196
+ private fun getEntryTimestamp (preserveFileTimestamps : Boolean , entryTime : Long ): Long {
197
+ return if (preserveFileTimestamps) entryTime else ShadowCopyAction .CONSTANT_TIME_FOR_ZIP_ENTRIES
198
+ }
176
199
}
177
200
178
201
// 3. the relocated and isolated javaagent libs are merged together with the bootstrap libs (which undergo relocation
179
202
// in this task) and the upstream javaagent jar; duplicates are removed
180
203
shadowJar {
181
-
182
- dependsOn(isolateJavaagentLibs)
183
- configurations = listOf (bootstrapLibs, upstreamAgent)
204
+ configurations = listOf (bootstrapLibsClasspath, upstreamAgentClasspath)
184
205
185
206
// exclude slf4j-simple from the shadow jar as we use log4j2-slf4j with internal-logging instead
186
207
exclude(" inst/io/opentelemetry/javaagent/slf4j/simple/**" )
187
208
188
- from(isolateJavaagentLibs.get().outputs )
209
+ from(isolateJavaagentLibs)
189
210
190
211
archiveClassifier.set(" " )
191
212
192
- duplicatesStrategy = DuplicatesStrategy .EXCLUDE
213
+ duplicatesStrategy = DuplicatesStrategy .INCLUDE
214
+ failOnDuplicateEntries = true
193
215
194
- mergeServiceFiles {
195
- include(" inst/META-INF/services/*" )
216
+ mergeServiceFiles{
217
+ include(" inst/META-INF/services/**" )
218
+ path = " inst/META-INF/services"
219
+ }
220
+ filesNotMatching(" inst/META-INF/services/**" ) {
221
+ duplicatesStrategy = DuplicatesStrategy .EXCLUDE
196
222
}
197
- exclude(" **/module-info.class" )
198
223
relocatePackages(this )
199
224
transform(injectSpanValueFieldTransformer)
200
225
0 commit comments