-
Notifications
You must be signed in to change notification settings - Fork 986
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
steverao
wants to merge
2
commits into
open-telemetry:main
Choose a base branch
from
steverao:distro
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
plugins { | ||
id("otel.java-conventions") | ||
} | ||
|
||
dependencies { | ||
} | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.Copilot uses AI. Check for mistakes.