Skip to content

Convert distro build scripts from Groovy to Kotlin DSL #14176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
127 changes: 0 additions & 127 deletions examples/distro/agent/build.gradle

This file was deleted.

135 changes: 135 additions & 0 deletions examples/distro/agent/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id("otel.java-conventions")
id("otel.shadow-conventions")
}

base.archivesName.set("otel-javaagent")

java {
withJavadocJar()
withSourcesJar()
}

// this configuration collects libs that will be placed in the bootstrap classloader
val bootstrapLibs: Configuration by configurations.creating {
isCanBeResolved = true
isCanBeConsumed = false
}
// this configuration collects libs that will be placed in the agent classloader, isolated from the instrumented application code
val javaagentLibs: Configuration by configurations.creating {
isCanBeResolved = true
isCanBeConsumed = false
}
// this configuration stores the upstream agent dep that's extended by this project
val upstreamAgent: Configuration by configurations.creating {
isCanBeResolved = true
isCanBeConsumed = false
}

val otelInstrumentationVersion: String by rootProject.extra

dependencies {
add("upstreamAgent", platform(project(":dependencyManagement")))
bootstrapLibs(project(":bootstrap"))

javaagentLibs(project(":custom"))
javaagentLibs(project(":instrumentation:servlet-3"))

upstreamAgent("io.opentelemetry.javaagent:opentelemetry-javaagent")
}

fun CopySpec.isolateClasses(jars: Iterable<File>) {
jars.forEach {
from(zipTree(it)) {
into("inst")
rename("^(.*)\\.class\$", "\$1.classdata")
// Rename LICENSE file since it clashes with license dir on non-case sensitive FSs (i.e. Mac)
rename("^LICENSE\$", "LICENSE.renamed")
exclude("META-INF/INDEX.LIST")
exclude("META-INF/*.DSA")
exclude("META-INF/*.SF")
exclude("META-INF/maven/**")
exclude("META-INF/MANIFEST.MF")
}
}
}

tasks {
jar {
enabled = false
}

processResources {
from(rootProject.file("licenses")) {
into("META-INF/licenses")
}
}

// building the final javaagent jar is done in 3 steps:

// 1. all distro specific javaagent libs are relocated
val relocateJavaagentLibs by registering(ShadowJar::class) {
configurations = listOf(javaagentLibs)

duplicatesStrategy = DuplicatesStrategy.FAIL

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

dependencies {
// exclude known bootstrap dependencies - they can't appear in the inst/ directory
exclude(dependency("org.slf4j:slf4j-api"))
exclude(dependency("io.opentelemetry:opentelemetry-api"))
exclude(dependency("io.opentelemetry:opentelemetry-context"))
exclude(dependency("io.opentelemetry:opentelemetry-api-incubator"))
}
}

// 2. the distro javaagent libs are then isolated - moved to the inst/ directory
// having a separate task for isolating javaagent libs is required to avoid duplicates with the upstream javaagent
// duplicatesStrategy in shadowJar won't be applied when adding files with with(CopySpec) because each CopySpec has
// its own duplicatesStrategy
val isolateJavaagentLibs by registering(Copy::class) {
dependsOn(relocateJavaagentLibs)
isolateClasses(relocateJavaagentLibs.get().outputs.files)

into(layout.buildDirectory.dir("isolated/javaagentLibs"))
}

// 3. the relocated and isolated javaagent libs are merged together with the bootstrap libs (which undergo relocation
// in this task) and the upstream javaagent jar; duplicates are removed
shadowJar {
configurations = listOf(bootstrapLibs, upstreamAgent)

dependsOn(isolateJavaagentLibs)
from(isolateJavaagentLibs.get().outputs)

archiveClassifier.set("all")

duplicatesStrategy = DuplicatesStrategy.EXCLUDE

mergeServiceFiles {
include("inst/META-INF/services/*")
}
exclude("**/module-info.class")

manifest {
attributes(
mapOf(
"Main-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent",
"Agent-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent",
"Premain-Class" to "io.opentelemetry.javaagent.OpenTelemetryAgent",
"Can-Redefine-Classes" to true,
"Can-Retransform-Classes" to true,
"Implementation-Vendor" to "Demo",
"Implementation-Version" to "demo-${project.version}-otel-$otelInstrumentationVersion",
),
)
}
}

assemble {
dependsOn(shadowJar)
}
}
6 changes: 0 additions & 6 deletions examples/distro/bootstrap/build.gradle

This file was deleted.

6 changes: 6 additions & 0 deletions examples/distro/bootstrap/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
plugins {
id("otel.java-conventions")
}

dependencies {
}
Comment on lines +3 to +6
Copy link
Preview

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This dependencies block is empty and can be removed to declutter the build script.

Suggested change
}
dependencies {
}
}

Copilot uses AI. Check for mistakes.

87 changes: 0 additions & 87 deletions examples/distro/build.gradle

This file was deleted.

10 changes: 10 additions & 0 deletions examples/distro/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
id("otel.instrumentation-conventions")
}

group = "io.opentelemetry.example"
version = "1.0-SNAPSHOT"

subprojects {
version = rootProject.version
}
Loading