@@ -141,23 +141,43 @@ tasks {
141141 archiveFileName.set(" bootstrapLibs.jar" )
142142 }
143143
144- val relocateBaseJavaagentLibs by registering(ShadowJar ::class ) {
144+ val relocateBaseJavaagentLibsTmp by registering(ShadowJar ::class ) {
145145 configurations = listOf (baseJavaagentLibs)
146146
147147 excludeBootstrapClasses()
148148
149149 duplicatesStrategy = DuplicatesStrategy .FAIL
150150
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+
151161 archiveFileName.set(" baseJavaagentLibs-relocated.jar" )
152162 }
153163
154- val relocateJavaagentLibs by registering(ShadowJar ::class ) {
164+ val relocateJavaagentLibsTmp by registering(ShadowJar ::class ) {
155165 configurations = listOf (javaagentLibs)
156166
157167 excludeBootstrapClasses()
158168
159169 duplicatesStrategy = DuplicatesStrategy .FAIL
160170
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+
161181 archiveFileName.set(" javaagentLibs-relocated.jar" )
162182 }
163183
@@ -363,6 +383,24 @@ fun CopySpec.isolateClasses(jar: Provider<RegularFile>) {
363383 }
364384}
365385
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+
366404// exclude bootstrap projects from javaagent libs - they won't be added to inst/
367405fun ShadowJar.excludeBootstrapClasses () {
368406 dependencies {
0 commit comments