From 0f052e34558b2f339d92baa332d20785142e8126 Mon Sep 17 00:00:00 2001 From: Bruce Bujon Date: Mon, 23 Nov 2026 13:45:21 +0100 Subject: [PATCH] Resolve tip from the builder image LATEST_VERSION The CI builder images export LATEST_VERSION, the latest GA Java major version, next to the JAVA_X_HOME of any early-access JDK. Resolve "tip" from it in Gradle and in the CI Visibility upload script, falling back to the highest installed JDK when it is absent, so a new EA JDK in the image no longer needs a dd-trace-java change. Co-Authored-By: Claude Opus 5.5 --- .gitlab/upload_ciapp.sh | 30 +++++++++------- .../plugin/testJvmConstraints/TestJvmSpec.kt | 35 ++++++++++--------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/.gitlab/upload_ciapp.sh b/.gitlab/upload_ciapp.sh index bcbcf5d5466..da0f257bcf8 100755 --- a/.gitlab/upload_ciapp.sh +++ b/.gitlab/upload_ciapp.sh @@ -11,21 +11,25 @@ if [ -n "$TEST_JVM" ]; then JAVA_BIN="" RESOLVED_JVM="$TEST_JVM" if [ "$TEST_JVM" = "tip" ]; then - # Resolve "tip" to the highest available JAVA_*_HOME version - MAX_VER=0 - for var in $(compgen -v JAVA_ | grep -E '^JAVA_[0-9]+_HOME$'); do - ver="${var#JAVA_}" - ver="${ver%_HOME}" - # TODO(JDK-28-EA): remove after GA (tip will move to 28) - if [ "$ver" = "28" ]; then - continue + if [[ "${LATEST_VERSION:-}" =~ ^[0-9]+$ ]]; then + # Resolve "tip" to the latest GA version set by the builder image, ignoring early-access JDKs + RESOLVED_JVM="$LATEST_VERSION" + else + if [ -n "${LATEST_VERSION:-}" ]; then + echo "Warning: LATEST_VERSION='$LATEST_VERSION' is not a Java major version, ignoring it" >&2 fi - if [ "$ver" -gt "$MAX_VER" ] 2>/dev/null; then - MAX_VER="$ver" + # Resolve "tip" to the highest available JAVA_*_HOME version + MAX_VER=0 + for var in $(compgen -v JAVA_ | grep -E '^JAVA_[0-9]+_HOME$'); do + ver="${var#JAVA_}" + ver="${ver%_HOME}" + if [ "$ver" -gt "$MAX_VER" ] 2>/dev/null; then + MAX_VER="$ver" + fi + done + if [ "$MAX_VER" -gt 0 ] 2>/dev/null; then + RESOLVED_JVM="$MAX_VER" fi - done - if [ "$MAX_VER" -gt 0 ] 2>/dev/null; then - RESOLVED_JVM="$MAX_VER" fi fi if [[ "$RESOLVED_JVM" =~ ^[A-Za-z0-9_]+$ ]]; then diff --git a/buildSrc/src/main/kotlin/datadog/gradle/plugin/testJvmConstraints/TestJvmSpec.kt b/buildSrc/src/main/kotlin/datadog/gradle/plugin/testJvmConstraints/TestJvmSpec.kt index 76c9f770e44..65eaaa125c5 100644 --- a/buildSrc/src/main/kotlin/datadog/gradle/plugin/testJvmConstraints/TestJvmSpec.kt +++ b/buildSrc/src/main/kotlin/datadog/gradle/plugin/testJvmConstraints/TestJvmSpec.kt @@ -36,15 +36,11 @@ class TestJvmSpec(val project: Project) { companion object { const val TEST_JVM = "testJvm" - // TODO(JDK-28-EA): remove after GA (tip will move to 28) - internal fun resolveTipJavaVersion(javaVersions: List): String { - val tipJavaVersions = javaVersions.filterNot { it == 28 } - if (tipJavaVersions.isEmpty()) { - throw GradleException("No Java installations found for tip after excluding Java 28.") - } - - return tipJavaVersions.max().toString() - } + /** + * Environment variable set by the CI builder images to the latest GA Java major version, which + * early-access JDKs installed alongside it must not replace as `tip`. + */ + const val LATEST_JDK_VERSION_ENV = "LATEST_VERSION" } /** @@ -53,7 +49,8 @@ class TestJvmSpec(val project: Project) { val testJvmProperty: Provider = project.providers.gradleProperty(TEST_JVM) /** - * Normalized `tip` string that's set to the highest JAVA_X_HOME version found in environment variables. + * Normalized `tip` string that's set to the `LATEST_VERSION` environment variable when present, or + * to the highest Java version found via toolchains or JAVA_X_HOME environment variables otherwise. */ val normalizedTestJvm: Provider = testJvmProperty.map { testJvm -> if (testJvm.isBlank()) { @@ -62,14 +59,20 @@ class TestJvmSpec(val project: Project) { when (testJvm) { "tip" -> { - val javaVersions = discoverJavaVersionsViaToolchains() - ?: discoverJavaVersionsViaEnvVars() + val latestJdkVersion = project.providers.environmentVariable(LATEST_JDK_VERSION_ENV).orNull + if (latestJdkVersion != null) { + latestJdkVersion.toIntOrNull()?.takeIf { it > 0 }?.toString() + ?: throw GradleException("$LATEST_JDK_VERSION_ENV must be a Java major version, got '$latestJdkVersion'.") + } else { + val javaVersions = discoverJavaVersionsViaToolchains() + ?: discoverJavaVersionsViaEnvVars() + + if (javaVersions.isEmpty()) { + throw GradleException("No Java installations found via toolchains or JAVA_X_HOME environment variables.") + } - if (javaVersions.isEmpty()) { - throw GradleException("No Java installations found via toolchains or JAVA_X_HOME environment variables.") + javaVersions.max().toString() } - - resolveTipJavaVersion(javaVersions) // TODO(JDK-28-EA): revert back to "javaVersions.max().toString()" after GA } else -> testJvm