diff --git a/build.gradle.kts b/build.gradle.kts index dee222f..017ce92 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,6 +2,7 @@ plugins { java `maven-publish` signing + id("com.gradleup.shadow") id("pl.allegro.tech.build.axion-release") id("io.github.gradle-nexus.publish-plugin") } @@ -63,6 +64,16 @@ tasks.named("sourcesJar") { from(allSources()) } +// produce "-all" jar with a shaded copy of ASM +tasks.shadowJar { + dependsOn(embed) + from(embed.map { zipTree(it) }) + relocate("org.objectweb.asm", "datadog.instrument.asm") +} +tasks.assemble { + dependsOn(tasks.shadowJar) +} + publishing { publications { create("maven") { @@ -89,6 +100,16 @@ publishing { developerConnection = "scm:git@github.com:datadog/dd-instrument-java.git" url = "https://github.com/datadog/dd-instrument-java" } + withXml { + // mark ASM dependency as optional + var doc = asElement().ownerDocument + var deps = doc.getElementsByTagName("dependency") + for (i in 0 ..< deps.length) { + var optional = doc.createElement("optional") + optional.textContent = "true" + deps.item(i).appendChild(optional) + } + } } } } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 88173a8..6f6599b 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -9,6 +9,7 @@ repositories { dependencies { // needed to re-use the 'libs' version catalog between the main project and buildSrc implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) + implementation(libs.shadow) implementation(libs.spotless) implementation(libs.spotbugs) implementation(libs.axion.release) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bddc80a..e3b68d3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,6 @@ [versions] asm = "9.9" +shadow = "9.2.2" junit-jupiter = "5.13.4" junit-platform = "1.13.4" assertj = "3.27.5" @@ -12,6 +13,7 @@ jmh-plugin = "0.7.3" [libraries] asm = { module = "org.ow2.asm:asm", version.ref = "asm" } +shadow = { module = "com.gradleup.shadow:shadow-gradle-plugin", version.ref = "shadow" } junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" } junit-launcher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junit-platform" } assertj-core = { module = "org.assertj:assertj-core", version.ref = "assertj" }