diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07acc884d07..4c918efc6f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,6 +92,14 @@ jobs: with: java-version: ${{ matrix.java.version }} distribution: 'temurin' + - name: Set up JDK 21 on an experimental platform + if: matrix.java.experimental + uses: actions/setup-java@v4 + with: + # Install JDK 21 second, to make it the default on which gradle runs. + # This unfortunately also means that all tests run on JDK 21 instead of the newer version. + java-version: 21 + distribution: 'temurin' # Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies. # See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md @@ -100,6 +108,9 @@ jobs: - name: Run test script checker/bin-devel/test-${{ matrix.script }} run: ./checker/bin-devel/test-${{ matrix.script }}.sh + # Set the compiler version to use, allowing us to e.g. run Java 23 while gradle does not work + # on Java 23 yet. This only tests the compiler, it does not use that version to run the tests. + env: ORG_GRADLE_PROJECT_useJdkCompiler=${{ matrix.java.version }} # Sanity tests on Windows and MacOS. otheros: diff --git a/build.gradle b/build.gradle index f128f18132a..0d77d5a956b 100644 --- a/build.gradle +++ b/build.gradle @@ -387,15 +387,17 @@ allprojects { // Add standard javac options tasks.withType(JavaCompile) { compilationTask -> dependsOn(':installGitHooks') - boolean jdk21Compiler = project.getProperties().getOrDefault('useJdk21Compiler', false) - if (!isJava8 && jdk21Compiler) { - // This uses the Java 21 compiler to compile all code, like we do for a release. + int useJdkCompiler = project.getProperties().getOrDefault('useJdkCompiler', 21) + boolean useToolchains = (JavaVersion.current() != useJdkCompiler) + if (!isJava8 && useToolchains) { + // This uses the requested Java compiler to compile all code. + // If no version is requested, we use Java 21, like we do for a release. // CI test test-cftests-junit-jdk21 then runs the JUnit tests on the different JDK versions, // to ensure there is no version mismatch between compiled-against javac API and runtime API. // https://docs.gradle.org/current/userguide/toolchains.html // This property is final on Java 8, so don't set it then. javaCompiler = javaToolchains.compilerFor { - languageVersion = JavaLanguageVersion.of(21) + languageVersion = JavaLanguageVersion.of(useJdkCompiler) } } @@ -459,7 +461,7 @@ allprojects { // warnings are suppressible with a "// fall through" comment. // -classfile: classgraph jar file and https://bugs.openjdk.org/browse/JDK-8190452 String lint = '-Xlint:-options,-fallthrough,-classfile' - if (isJava21plus || jdk21Compiler) { + if (useJdkCompiler >= 21) { // TODO: Ignore this-escape for now, we may want to review and suppress each one later. lint +=',-this-escape' } diff --git a/checker/bin-devel/test-cftests-junit-jdk21.sh b/checker/bin-devel/test-cftests-junit-jdk21.sh index 449e7a00b48..fe20e2caf60 100755 --- a/checker/bin-devel/test-cftests-junit-jdk21.sh +++ b/checker/bin-devel/test-cftests-junit-jdk21.sh @@ -8,7 +8,7 @@ echo "SHELLOPTS=${SHELLOPTS}" SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" # shellcheck disable=SC1090# In newer shellcheck than 0.6.0, pass: "-P SCRIPTDIR" (literally) -export ORG_GRADLE_PROJECT_useJdk21Compiler=true +export ORG_GRADLE_PROJECT_useJdkCompiler=21 source "$SCRIPTDIR"/clone-related.sh