Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,43 @@ tasks {
archiveFileName.set("bootstrapLibs.jar")
}

val relocateBaseJavaagentLibs by registering(ShadowJar::class) {
val relocateBaseJavaagentLibsTmp by registering(ShadowJar::class) {
configurations = listOf(baseJavaagentLibs)

excludeBootstrapClasses()

duplicatesStrategy = DuplicatesStrategy.FAIL

archiveFileName.set("baseJavaagentLibs-relocated-tmp.jar")
}

val relocateBaseJavaagentLibs by registering(Jar::class) {
dependsOn(relocateBaseJavaagentLibsTmp)

copyByteBuddy(relocateBaseJavaagentLibsTmp.get().archiveFile)

duplicatesStrategy = DuplicatesStrategy.FAIL

archiveFileName.set("baseJavaagentLibs-relocated.jar")
}

val relocateJavaagentLibs by registering(ShadowJar::class) {
val relocateJavaagentLibsTmp by registering(ShadowJar::class) {
configurations = listOf(javaagentLibs)

excludeBootstrapClasses()

duplicatesStrategy = DuplicatesStrategy.FAIL

archiveFileName.set("javaagentLibs-relocated-tmp.jar")
}

val relocateJavaagentLibs by registering(Jar::class) {
dependsOn(relocateJavaagentLibsTmp)

copyByteBuddy(relocateJavaagentLibsTmp.get().archiveFile)

duplicatesStrategy = DuplicatesStrategy.FAIL

archiveFileName.set("javaagentLibs-relocated.jar")
}

Expand Down Expand Up @@ -363,6 +383,24 @@ fun CopySpec.isolateClasses(jar: Provider<RegularFile>) {
}
}

fun CopySpec.copyByteBuddy(jar: Provider<RegularFile>) {
// Byte buddy jar includes classes compiled for java 5 at the root of the jar and the same classes
// compiled for java 8 under META-INF/versions/9. Here we move the classes from
// META-INF/versions/9/net/bytebuddy to net/bytebuddy to get rid of the duplicate classes.
from(zipTree(jar)) {
eachFile {
if (path.startsWith("net/bytebuddy/") &&
// this is our class that we have placed in the byte buddy package, need to preserve it
!path.startsWith("net/bytebuddy/agent/builder/AgentBuilderUtil")) {
exclude()
} else if (path.startsWith("META-INF/versions/9/net/bytebuddy/")) {
path = path.removePrefix("META-INF/versions/9/")
}
}
includeEmptyDirs = false
}
}

// exclude bootstrap projects from javaagent libs - they won't be added to inst/
fun ShadowJar.excludeBootstrapClasses() {
dependencies {
Expand Down
Loading