Move min/max java properties to an extension class
ADD
buildSrc/src/main/kotlin/io/opentelemetry/instrumentation/gradle/OtelJavaExtension.kt
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.instrumentation.gradle
+
+import org.gradle.api.JavaVersion
+import org.gradle.api.provider.Property
+
+abstract class OtelJavaExtension {
+ abstract val minJavaVersionSupported: Property<JavaVersion>
+
+ abstract val maxJavaVersionForTests: Property<JavaVersion>
+
+ init {
+ minJavaVersionSupported.convention(JavaVersion.VERSION_1_8)
+ }
+}

MODIFY
buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts
buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts
+import io.opentelemetry.instrumentation.gradle.OtelJavaExtension
import java.time.Duration
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
@@ -13,6 +14,8 @@ plugins {
id("otel.spotless-conventions")
}
+val otelJava = extensions.create<OtelJavaExtension>("otelJava")
+
afterEvaluate {
if (findProperty("mavenGroupId") == "io.opentelemetry.javaagent.instrumentation") {
base.archivesBaseName = "opentelemetry-javaagent-${base.archivesBaseName}"
@@ -35,14 +38,9 @@ if (applyCodeCoverage) {
apply(from = "${rootDir}/gradle/jacoco.gradle")
}
-val minJavaVersionSupported = project.findProperty("minJavaVersionSupported")?.let(JavaVersion::toVersion)
- ?: JavaVersion.VERSION_1_8
-val maxJavaVersionForTests = project.findProperty("maxJavaVersionForTests")?.let(JavaVersion::toVersion)
-
java {
toolchain {
- languageVersion.set(JavaLanguageVersion.of(
- Math.max(minJavaVersionSupported.majorVersion.toInt(), DEFAULT_JAVA_VERSION.majorVersion.toInt())))
+ languageVersion.set(otelJava.minJavaVersionSupported.map { JavaLanguageVersion.of(Math.max(it.majorVersion.toInt(), DEFAULT_JAVA_VERSION.majorVersion.toInt())) })
}
// See https://docs.gradle.org/current/userguide/upgrading_version_5.html, Automatic target JVM version
@@ -53,19 +51,21 @@ java {
tasks.withType<JavaCompile>().configureEach {
with(options) {
- release.set(minJavaVersionSupported.majorVersion.toInt())
+ release.set(otelJava.minJavaVersionSupported.map { it.majorVersion.toInt() })
compilerArgs.add("-Werror")
}
}
// Groovy and Scala compilers don't actually understand --release option
+afterEvaluate {
tasks.withType<GroovyCompile>().configureEach {
- sourceCompatibility = minJavaVersionSupported.majorVersion
- targetCompatibility = minJavaVersionSupported.majorVersion
+ sourceCompatibility = otelJava.minJavaVersionSupported.get().majorVersion
+ targetCompatibility = otelJava.minJavaVersionSupported.get().majorVersion
}
tasks.withType<ScalaCompile>().configureEach {
- sourceCompatibility = minJavaVersionSupported.majorVersion
- targetCompatibility = minJavaVersionSupported.majorVersion
+ sourceCompatibility = otelJava.minJavaVersionSupported.get().majorVersion
+ targetCompatibility = otelJava.minJavaVersionSupported.get().majorVersion
+ }
}
evaluationDependsOn(":dependencyManagement")
@@ -172,16 +172,16 @@ normalization {
}
fun isJavaVersionAllowed(version: JavaVersion): Boolean {
- if (minJavaVersionSupported.compareTo(version) > 0) {
+ if (otelJava.minJavaVersionSupported.get().compareTo(version) > 0) {
return false
}
- if (maxJavaVersionForTests != null && maxJavaVersionForTests.compareTo(version) < 0) {
+ if (otelJava.maxJavaVersionForTests.isPresent() && otelJava.maxJavaVersionForTests.get().compareTo(version) < 0) {
return false
}
return true
}
-val testJavaVersion = rootProject.findProperty("testJavaVersion")?.let(JavaVersion::toVersion)
+val testJavaVersion = gradle.startParameter.projectProperties.get("testJavaVersion")?.let(JavaVersion::toVersion)
val resourceClassesCsv = listOf("Host", "Os", "Process", "ProcessRuntime").map { "io.opentelemetry.sdk.extension.resources.${it}ResourceProvider" }.joinToString(",")
tasks.withType<Test>().configureEach {
useJUnitPlatform()
@@ -219,7 +219,10 @@ tasks.withType<Test>().configureEach {
testLogging {
exceptionFormat = TestExceptionFormat.FULL
}
+}
+afterEvaluate {
+ tasks.withType<Test>().configureEach {
if (testJavaVersion != null) {
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(testJavaVersion.majorVersion))
@@ -229,17 +232,14 @@ tasks.withType<Test>().configureEach {
// We default to testing with Java 11 for most tests, but some tests don't support it, where we change
// the default test task's version so commands like `./gradlew check` can test all projects regardless
// of Java version.
- if (!isJavaVersionAllowed(DEFAULT_JAVA_VERSION) && maxJavaVersionForTests != null) {
+ if (!isJavaVersionAllowed(DEFAULT_JAVA_VERSION) && otelJava.maxJavaVersionForTests.isPresent) {
javaLauncher.set(javaToolchains.launcherFor {
- languageVersion.set(JavaLanguageVersion.of(maxJavaVersionForTests.majorVersion))
+ languageVersion.set(JavaLanguageVersion.of(otelJava.maxJavaVersionForTests.get().majorVersion))
})
}
}
-}
-afterEvaluate {
if (plugins.hasPlugin("org.unbroken-dome.test-sets") && configurations.findByName("latestDepTestRuntime") != null) {
- tasks.withType<Test>().configureEach {
doFirst {
val testArtifacts = configurations.testRuntimeClasspath.get().resolvedConfiguration.resolvedArtifacts
val latestTestArtifacts = configurations.getByName("latestDepTestRuntimeClasspath").resolvedConfiguration.resolvedArtifacts

MODIFY
instrumentation/async-http-client/async-http-client-2.0/javaagent/async-http-client-2.0-javaagent.gradle
instrumentation/async-http-client/async-http-client-2.0/javaagent/async-http-client-2.0-javaagent.gradle
-ext {
- //AHC uses Unsafe and so does not run on later java version
- maxJavaVersionForTests = JavaVersion.VERSION_1_8
-}
-
apply from: "$rootDir/gradle/instrumentation.gradle"
muzzle {
@@ -23,6 +18,11 @@ dependencies {
testInstrumentation project(':instrumentation:netty:netty-4.0:javaagent')
}
+otelJava {
+ //AHC uses Unsafe and so does not run on later java version
+ maxJavaVersionForTests = JavaVersion.VERSION_1_8
+}
+
// async-http-client 2.0.0 does not work with Netty versions newer than this due to referencing an
// internal file.
if (!testLatestDeps) {

MODIFY
instrumentation/java-http-client/javaagent/java-http-client-javaagent.gradle
instrumentation/java-http-client/javaagent/java-http-client-javaagent.gradle
-ext {
- minJavaVersionSupported = JavaVersion.VERSION_11
-}
-
apply from: "$rootDir/gradle/instrumentation.gradle"
muzzle {
@@ -9,3 +5,7 @@ muzzle {
coreJdk()
}
}
+
+otelJava {
+ minJavaVersionSupported = JavaVersion.VERSION_11
+}
\ No newline at end of file

MODIFY
instrumentation/jetty/jetty-11.0/javaagent/jetty-11.0-javaagent.gradle
instrumentation/jetty/jetty-11.0/javaagent/jetty-11.0-javaagent.gradle
-ext {
- minJavaVersionSupported = JavaVersion.VERSION_11
-}
-
apply from: "$rootDir/gradle/instrumentation.gradle"
muzzle {
@@ -24,3 +20,7 @@ dependencies {
testLibrary "org.eclipse.jetty:jetty-servlet:11.0.0"
}
+
+otelJava {
+ minJavaVersionSupported = JavaVersion.VERSION_11
+}

MODIFY
instrumentation/play/play-2.4/javaagent/play-2.4-javaagent.gradle
instrumentation/play/play-2.4/javaagent/play-2.4-javaagent.gradle
-ext {
- // Play doesn't work with Java 9+ until 2.6.12
- maxJavaVersionForTests = JavaVersion.VERSION_1_8
-}
-
apply from: "$rootDir/gradle/instrumentation.gradle"
muzzle {
@@ -27,6 +22,11 @@ muzzle {
}
}
+otelJava {
+ // Play doesn't work with Java 9+ until 2.6.12
+ maxJavaVersionForTests = JavaVersion.VERSION_1_8
+}
+
dependencies {
// TODO(anuraaga): Something about library configuration doesn't work well with scala compilation
// here.

MODIFY
instrumentation/play/play-2.6/javaagent/play-2.6-javaagent.gradle
instrumentation/play/play-2.6/javaagent/play-2.6-javaagent.gradle
-ext {
- // Play doesn't work with Java 9+ until 2.6.12
- maxJavaVersionForTests = JavaVersion.VERSION_1_8
-}
-
apply from: "$rootDir/gradle/instrumentation.gradle"
def scalaVersion = '2.11'
@@ -32,6 +27,11 @@ muzzle {
}
}
+otelJava {
+ // Play doesn't work with Java 9+ until 2.6.12
+ maxJavaVersionForTests = JavaVersion.VERSION_1_8
+}
+
dependencies {
// TODO(anuraaga): Something about library configuration doesn't work well with scala compilation
// here.

MODIFY
instrumentation/tapestry-5.4/javaagent/tapestry-5.4-javaagent.gradle
instrumentation/tapestry-5.4/javaagent/tapestry-5.4-javaagent.gradle
-ext {
- maxJavaVersionForTests = JavaVersion.VERSION_1_8
-}
-
apply from: "$rootDir/gradle/instrumentation.gradle"
muzzle {
@@ -13,6 +9,10 @@ muzzle {
}
}
+otelJava {
+ maxJavaVersionForTests = JavaVersion.VERSION_1_8
+}
+
dependencies {
library 'org.apache.tapestry:tapestry-core:5.4.0'

MODIFY
smoke-tests/smoke-tests.gradle
smoke-tests/smoke-tests.gradle
import java.time.Duration
-ext {
+apply plugin: "otel.java-conventions"
+
+description = 'smoke-tests'
+
+otelJava {
// we only need to run the Spock test itself under a single Java version, and the Spock test in
// turn is parameterized and runs the test using different docker containers that run different
// Java versions
@@ -8,10 +12,6 @@ ext {
maxJavaVersionForTests = JavaVersion.VERSION_11
}
-apply plugin: "otel.java-conventions"
-
-description = 'smoke-tests'
-
def dockerJavaVersion = "3.2.5"
dependencies {
api "org.spockframework:spock-core"

Move min/max java properties to an extension class (#3307)