Skip to content

Commit e9fcf73

Browse files
committed
Convert examples/distro build from Groovy to Kotlin DSL
Convert the examples/distro/build.gradle to build.gradle.kts using Kotlin DSL syntax. This improves type safety and IDE support while maintaining all existing functionality. Key changes: - Rename build.gradle to build.gradle.kts - Convert Groovy syntax to Kotlin DSL: - Use mapOf() instead of Groovy maps - Use apply(plugin = "name") instead of apply plugin: "name" - Use plugins.withType<JavaPlugin> for deferred configuration - Use tasks.named<Type>() for task configuration - Update .github/scripts/update-sdk-version.sh to match new Kotlin DSL syntax ("opentelemetrySdk" to "version" format) - Preserve extra["versions"] and extra["deps"] for use by Groovy subproject build files and applied scripts - Set Java 8 release only for main source compilation (compileJava), allowing tests to use modern Java features The conversion maintains equivalence to the original Groovy build while following Gradle Kotlin DSL best practices. Signed-off-by: Sibasis Padhi <sibasis.padhi@gmail.com>
1 parent 16422e8 commit e9fcf73

3 files changed

Lines changed: 89 additions & 88 deletions

File tree

.github/scripts/update-sdk-version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ version=$1
44

55
sed -Ei "s/val otelSdkVersion = \"[^\"]*\"/val otelSdkVersion = \"$version\"/" dependencyManagement/build.gradle.kts
66

7-
sed -Ei "s/(opentelemetrySdk *: )\"[^\"]*\"/\1\"$version\"/" examples/distro/build.gradle
7+
sed -Ei "s/(\"opentelemetrySdk\" to )\"[^\"]*\"/\1\"$version\"/" examples/distro/build.gradle.kts
88

99
sed -Ei "s/(opentelemetrySdk *: )\"[^\"]*\"/\1\"$version\"/" examples/extension/build.gradle

examples/distro/build.gradle

Lines changed: 0 additions & 87 deletions
This file was deleted.

examples/distro/build.gradle.kts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
group = "io.opentelemetry.example"
2+
version = "1.0-SNAPSHOT"
3+
4+
buildscript {
5+
repositories {
6+
maven {
7+
url = uri("https://plugins.gradle.org/m2/")
8+
}
9+
maven {
10+
name = "sonatype"
11+
url = uri("https://central.sonatype.com/repository/maven-snapshots/")
12+
}
13+
}
14+
dependencies {
15+
classpath("com.diffplug.spotless:spotless-plugin-gradle:8.1.0")
16+
classpath("com.gradleup.shadow:shadow-gradle-plugin:9.3.1")
17+
classpath("io.opentelemetry.instrumentation:gradle-plugins:2.24.0-alpha-SNAPSHOT")
18+
}
19+
}
20+
21+
subprojects {
22+
version = rootProject.version
23+
24+
apply(plugin = "java")
25+
apply(plugin = "com.diffplug.spotless")
26+
27+
val versions = mapOf(
28+
// this line is managed by .github/scripts/update-sdk-version.sh
29+
"opentelemetrySdk" to "1.57.0",
30+
31+
// these lines are managed by .github/scripts/update-version.sh
32+
"opentelemetryJavaagent" to "2.24.0-SNAPSHOT",
33+
"opentelemetryJavaagentAlpha" to "2.24.0-alpha-SNAPSHOT",
34+
35+
"autoservice" to "1.1.1"
36+
)
37+
38+
val deps = mapOf(
39+
"autoservice" to listOf(
40+
"com.google.auto.service:auto-service:${versions["autoservice"]}",
41+
"com.google.auto.service:auto-service-annotations:${versions["autoservice"]}"
42+
)
43+
)
44+
45+
extra["versions"] = versions
46+
extra["deps"] = deps
47+
48+
repositories {
49+
mavenCentral()
50+
maven {
51+
name = "sonatype"
52+
url = uri("https://central.sonatype.com/repository/maven-snapshots/")
53+
}
54+
}
55+
56+
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
57+
java {
58+
googleJavaFormat()
59+
licenseHeaderFile(rootProject.file("../../buildscripts/spotless.license.java"), "(package|import|public)")
60+
target("src/**/*.java")
61+
}
62+
}
63+
64+
plugins.withType<JavaPlugin> {
65+
dependencies {
66+
add("implementation", platform("io.opentelemetry:opentelemetry-bom:${versions["opentelemetrySdk"]}"))
67+
68+
// these serve as a test of the instrumentation boms
69+
add("implementation", platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom:${versions["opentelemetryJavaagent"]}"))
70+
add("implementation", platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:${versions["opentelemetryJavaagentAlpha"]}"))
71+
72+
add("testImplementation", "org.mockito:mockito-core:5.21.0")
73+
74+
add("testImplementation", enforcedPlatform("org.junit:junit-bom:5.14.2"))
75+
add("testImplementation", "org.junit.jupiter:junit-jupiter-api")
76+
add("testRuntimeOnly", "org.junit.jupiter:junit-jupiter-engine")
77+
add("testRuntimeOnly", "org.junit.platform:junit-platform-launcher")
78+
}
79+
}
80+
81+
tasks.named<Test>("test") {
82+
useJUnitPlatform()
83+
}
84+
85+
tasks.named<JavaCompile>("compileJava") {
86+
options.release.set(8)
87+
}
88+
}

0 commit comments

Comments
 (0)