Skip to content

Commit 151e345

Browse files
authored
Implement min java version gradle tooling from instrumentation repo (#7801)
1 parent 41dcca4 commit 151e345

File tree

6 files changed

+34
-58
lines changed

6 files changed

+34
-58
lines changed

buildSrc/src/main/kotlin/io/opentelemetry/gradle/OtelJavaExtension.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55

66
package io.opentelemetry.gradle
77

8+
import org.gradle.api.JavaVersion
89
import org.gradle.api.provider.Property
910

1011
abstract class OtelJavaExtension {
1112
abstract val moduleName: Property<String>
13+
14+
abstract val minJavaVersionSupported: Property<JavaVersion>
15+
16+
init {
17+
minJavaVersionSupported.convention(JavaVersion.VERSION_1_8)
18+
}
1219
}

buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import io.opentelemetry.gradle.OtelJavaExtension
2+
import org.gradle.api.JavaVersion
23
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
34

45
plugins {
@@ -74,7 +75,7 @@ val testJavaVersion = gradle.startParameter.projectProperties.get("testJavaVersi
7475
tasks {
7576
withType<JavaCompile>().configureEach {
7677
with(options) {
77-
release.set(8)
78+
release.set(otelJava.minJavaVersionSupported.map { it.majorVersion.toInt() })
7879

7980
if (name != "jmhCompileGeneratedClasses") {
8081
compilerArgs.addAll(
@@ -108,14 +109,6 @@ tasks {
108109
withType<Test>().configureEach {
109110
useJUnitPlatform()
110111

111-
if (testJavaVersion != null) {
112-
javaLauncher.set(
113-
javaToolchains.launcherFor {
114-
languageVersion.set(JavaLanguageVersion.of(testJavaVersion.majorVersion))
115-
},
116-
)
117-
}
118-
119112
val defaultMaxRetries = if (System.getenv().containsKey("CI")) 2 else 0
120113
val maxTestRetries = gradle.startParameter.projectProperties["maxTestRetries"]?.toInt() ?: defaultMaxRetries
121114

@@ -174,6 +167,19 @@ tasks {
174167
}
175168
}
176169

170+
afterEvaluate {
171+
tasks.withType<Test>().configureEach {
172+
if (testJavaVersion != null) {
173+
javaLauncher.set(
174+
javaToolchains.launcherFor {
175+
languageVersion.set(JavaLanguageVersion.of(testJavaVersion.majorVersion))
176+
}
177+
)
178+
isEnabled = isEnabled && testJavaVersion >= otelJava.minJavaVersionSupported.get()
179+
}
180+
}
181+
}
182+
177183
// Add version information to published artifacts.
178184
plugins.withId("otel.publish-conventions") {
179185
tasks {
Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
1+
import org.gradle.api.JavaVersion
2+
13
plugins {
24
id("otel.java-conventions")
35
id("otel.publish-conventions")
46
}
57

68
description = "OpenTelemetry JDK HttpSender"
79
otelJava.moduleName.set("io.opentelemetry.exporter.sender.jdk.internal")
10+
otelJava.minJavaVersionSupported.set(JavaVersion.VERSION_11)
811

912
dependencies {
1013
implementation(project(":exporters:common"))
1114
implementation(project(":sdk:common"))
1215

1316
testImplementation("com.fasterxml.jackson.core:jackson-core")
1417
}
15-
16-
tasks {
17-
withType<JavaCompile>().configureEach {
18-
sourceCompatibility = "11"
19-
targetCompatibility = "11"
20-
options.release.set(11)
21-
}
22-
}
23-
24-
tasks.test {
25-
val testJavaVersion: String? by project
26-
enabled = !testJavaVersion.equals("8")
27-
}

integration-tests/graal-incubating/build.gradle.kts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import org.gradle.api.JavaVersion
2+
13
plugins {
24
id("otel.java-conventions")
35
id("org.graalvm.buildtools.native")
46
}
57

68
description = "OpenTelemetry Graal Integration Tests (Incubating)"
79
otelJava.moduleName.set("io.opentelemetry.graal.integration.tests.incubating")
10+
otelJava.minJavaVersionSupported.set(JavaVersion.VERSION_11)
811

912
sourceSets {
1013
main {
@@ -25,17 +28,6 @@ dependencies {
2528

2629
// org.graalvm.buildtools.native plugin requires java 11+ as of version 0.9.26
2730
// https://github.com/graalvm/native-build-tools/blob/master/docs/src/docs/asciidoc/index.adoc
28-
tasks {
29-
withType<JavaCompile>().configureEach {
30-
sourceCompatibility = "11"
31-
targetCompatibility = "11"
32-
options.release.set(11)
33-
}
34-
withType<Test>().configureEach {
35-
val testJavaVersion: String? by project
36-
enabled = !testJavaVersion.equals("8")
37-
}
38-
}
3931

4032
graalvmNative {
4133
binaries {

integration-tests/graal/build.gradle.kts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import org.gradle.api.JavaVersion
2+
13
plugins {
24
id("otel.java-conventions")
35
id("org.graalvm.buildtools.native")
46
}
57

68
description = "OpenTelemetry Graal Integration Tests"
79
otelJava.moduleName.set("io.opentelemetry.graal.integration.tests")
10+
otelJava.minJavaVersionSupported.set(JavaVersion.VERSION_11)
811

912
sourceSets {
1013
main {
@@ -23,17 +26,6 @@ dependencies {
2326

2427
// org.graalvm.buildtools.native plugin requires java 11+ as of version 0.9.26
2528
// https://github.com/graalvm/native-build-tools/blob/master/docs/src/docs/asciidoc/index.adoc
26-
tasks {
27-
withType<JavaCompile>().configureEach {
28-
sourceCompatibility = "11"
29-
targetCompatibility = "11"
30-
options.release.set(11)
31-
}
32-
withType<Test>().configureEach {
33-
val testJavaVersion: String? by project
34-
enabled = !testJavaVersion.equals("8")
35-
}
36-
}
3729

3830
graalvmNative {
3931
binaries {

javadoc-crawler/build.gradle.kts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.gradle.api.JavaVersion
2+
13
plugins {
24
id("otel.java-conventions")
35
}
@@ -9,22 +11,9 @@ dependencies {
911

1012
description = "OpenTelemetry Javadoc Crawler"
1113
otelJava.moduleName.set("io.opentelemetry.javadocs")
14+
otelJava.minJavaVersionSupported.set(JavaVersion.VERSION_17)
1215

1316
tasks {
14-
withType<JavaCompile>().configureEach {
15-
sourceCompatibility = "17"
16-
targetCompatibility = "17"
17-
options.release.set(17)
18-
}
19-
20-
// only test on java 17+
21-
val testJavaVersion: String? by project
22-
if (testJavaVersion != null && Integer.valueOf(testJavaVersion) < 17) {
23-
test {
24-
enabled = false
25-
}
26-
}
27-
2817
val crawl by registering(JavaExec::class) {
2918
dependsOn(classes)
3019

0 commit comments

Comments
 (0)