@@ -141,23 +141,43 @@ tasks {
141
141
archiveFileName.set(" bootstrapLibs.jar" )
142
142
}
143
143
144
- val relocateBaseJavaagentLibs by registering(ShadowJar ::class ) {
144
+ val relocateBaseJavaagentLibsTmp by registering(ShadowJar ::class ) {
145
145
configurations = listOf (baseJavaagentLibs)
146
146
147
147
excludeBootstrapClasses()
148
148
149
149
duplicatesStrategy = DuplicatesStrategy .FAIL
150
150
151
+ archiveFileName.set(" baseJavaagentLibs-relocated-tmp.jar" )
152
+ }
153
+
154
+ val relocateBaseJavaagentLibs by registering(Jar ::class ) {
155
+ dependsOn(relocateBaseJavaagentLibsTmp)
156
+
157
+ copyByteBuddy(relocateBaseJavaagentLibsTmp.get().archiveFile)
158
+
159
+ duplicatesStrategy = DuplicatesStrategy .FAIL
160
+
151
161
archiveFileName.set(" baseJavaagentLibs-relocated.jar" )
152
162
}
153
163
154
- val relocateJavaagentLibs by registering(ShadowJar ::class ) {
164
+ val relocateJavaagentLibsTmp by registering(ShadowJar ::class ) {
155
165
configurations = listOf (javaagentLibs)
156
166
157
167
excludeBootstrapClasses()
158
168
159
169
duplicatesStrategy = DuplicatesStrategy .FAIL
160
170
171
+ archiveFileName.set(" javaagentLibs-relocated-tmp.jar" )
172
+ }
173
+
174
+ val relocateJavaagentLibs by registering(Jar ::class ) {
175
+ dependsOn(relocateJavaagentLibsTmp)
176
+
177
+ copyByteBuddy(relocateJavaagentLibsTmp.get().archiveFile)
178
+
179
+ duplicatesStrategy = DuplicatesStrategy .FAIL
180
+
161
181
archiveFileName.set(" javaagentLibs-relocated.jar" )
162
182
}
163
183
@@ -363,6 +383,24 @@ fun CopySpec.isolateClasses(jar: Provider<RegularFile>) {
363
383
}
364
384
}
365
385
386
+ fun CopySpec.copyByteBuddy (jar : Provider <RegularFile >) {
387
+ // Byte buddy jar includes classes compiled for java 5 at the root of the jar and the same classes
388
+ // compiled for java 8 under META-INF/versions/9. Here we move the classes from
389
+ // META-INF/versions/9/net/bytebuddy to net/bytebuddy to get rid of the duplicate classes.
390
+ from(zipTree(jar)) {
391
+ eachFile {
392
+ if (path.startsWith(" net/bytebuddy/" ) &&
393
+ // this is our class that we have placed in the byte buddy package, need to preserve it
394
+ ! path.startsWith(" net/bytebuddy/agent/builder/AgentBuilderUtil" )) {
395
+ exclude()
396
+ } else if (path.startsWith(" META-INF/versions/9/net/bytebuddy/" )) {
397
+ path = path.removePrefix(" META-INF/versions/9/" )
398
+ }
399
+ }
400
+ includeEmptyDirs = false
401
+ }
402
+ }
403
+
366
404
// exclude bootstrap projects from javaagent libs - they won't be added to inst/
367
405
fun ShadowJar.excludeBootstrapClasses () {
368
406
dependencies {
0 commit comments