From 6e2049eb920f365142a99704f423035570d602e4 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 5 Feb 2025 11:34:28 +0000 Subject: [PATCH] Compile project with Java 24 and '-release' Java 17 Closes gh-45472 --- .github/actions/build/action.yml | 2 +- .../actions/prepare-gradle-build/action.yml | 4 ++-- .github/workflows/ci.yml | 11 ++++----- .sdkmanrc | 2 +- .../boot/build/JavaConventions.java | 16 ++++--------- .../boot/build/toolchain/ToolchainPlugin.java | 24 +++++++------------ .../ConditionalOnAvailableEndpointTests.java | 3 ++- .../endpoint/DisabledEndpoint.java | 3 ++- .../endpoint/SimpleEndpoint3.java | 3 ++- .../endpoint/SpecificEndpoint.java | 3 ++- .../spring-boot-loader-tools/build.gradle | 4 ++++ 11 files changed, 34 insertions(+), 41 deletions(-) diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index b45040d034..c7ebe868ef 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -35,7 +35,7 @@ inputs: java-version: description: 'Java version to compile and test with' required: false - default: '17' + default: '24' publish: description: 'Whether to publish artifacts ready for deployment to Artifactory' required: false diff --git a/.github/actions/prepare-gradle-build/action.yml b/.github/actions/prepare-gradle-build/action.yml index 6532ce7527..f33fdb7be0 100644 --- a/.github/actions/prepare-gradle-build/action.yml +++ b/.github/actions/prepare-gradle-build/action.yml @@ -23,7 +23,7 @@ inputs: java-version: description: 'Java version to use for the build' required: false - default: '17' + default: '24' runs: using: composite steps: @@ -39,7 +39,7 @@ runs: distribution: ${{ inputs.java-early-access == 'true' && 'temurin' || (inputs.java-distribution || 'liberica') }} java-version: | ${{ inputs.java-early-access == 'true' && format('{0}-ea', inputs.java-version) || inputs.java-version }} - ${{ inputs.java-toolchain == 'true' && '17' || '' }} + ${{ inputs.java-toolchain == 'true' && '24' || '' }} - name: Set Up Gradle With Read/Write Cache if: ${{ inputs.cache-read-only == 'false' }} uses: gradle/actions/setup-gradle@06832c7b30a0129d7fb559bcc6e43d26f6374244 # v4.3.1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c40454d091..3d662005d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,21 +18,20 @@ jobs: name: Windows java: - version: 17 - toolchain: false + toolchain: true - version: 21 - toolchain: false + toolchain: true - version: 22 - toolchain: false + toolchain: true - version: 23 toolchain: true - version: 24 - early-access: true - toolchain: true + toolchain: false exclude: - os: name: Linux java: - version: 17 + version: 24 - os: name: ${{ github.repository == 'spring-projects/spring-boot-commercial' && 'Windows' }} steps: diff --git a/.sdkmanrc b/.sdkmanrc index bea2d5156c..b41ba343b0 100644 --- a/.sdkmanrc +++ b/.sdkmanrc @@ -1,3 +1,3 @@ # Enable auto-env through the sdkman_auto_env config # Add key=value pairs of SDKs to use below -java=17.0.15-librca +java=24.0.1-librca diff --git a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java index a99b8ba405..721a3a35e2 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java @@ -235,28 +235,20 @@ class JavaConventions { if (!project.hasProperty("toolchainVersion")) { JavaPluginExtension javaPluginExtension = project.getExtensions().getByType(JavaPluginExtension.class); javaPluginExtension.setSourceCompatibility(JavaVersion.toVersion(SOURCE_AND_TARGET_COMPATIBILITY)); + javaPluginExtension.setTargetCompatibility(JavaVersion.toVersion(SOURCE_AND_TARGET_COMPATIBILITY)); } project.getTasks().withType(JavaCompile.class, (compile) -> { compile.getOptions().setEncoding("UTF-8"); + compile.getOptions().getRelease().set(17); List args = compile.getOptions().getCompilerArgs(); if (!args.contains("-parameters")) { args.add("-parameters"); } - if (project.hasProperty("toolchainVersion")) { - compile.setSourceCompatibility(SOURCE_AND_TARGET_COMPATIBILITY); - compile.setTargetCompatibility(SOURCE_AND_TARGET_COMPATIBILITY); - } - else if (buildingWithJava17(project)) { - args.addAll(Arrays.asList("-Werror", "-Xlint:unchecked", "-Xlint:deprecation", "-Xlint:rawtypes", - "-Xlint:varargs")); - } + args.addAll(Arrays.asList("-Werror", "-Xlint:unchecked", "-Xlint:deprecation", "-Xlint:rawtypes", + "-Xlint:varargs")); }); } - private boolean buildingWithJava17(Project project) { - return !project.hasProperty("toolchainVersion") && JavaVersion.current() == JavaVersion.VERSION_17; - } - private void configureSpringJavaFormat(Project project) { project.getPlugins().apply(SpringJavaFormatPlugin.class); project.getTasks().withType(Format.class, (Format) -> Format.setEncoding("UTF-8")); diff --git a/buildSrc/src/main/java/org/springframework/boot/build/toolchain/ToolchainPlugin.java b/buildSrc/src/main/java/org/springframework/boot/build/toolchain/ToolchainPlugin.java index b5e602d7fa..dc81ca7752 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/toolchain/ToolchainPlugin.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/toolchain/ToolchainPlugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,21 +16,17 @@ package org.springframework.boot.build.toolchain; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import org.gradle.api.Plugin; import org.gradle.api.Project; -import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.tasks.testing.Test; import org.gradle.jvm.toolchain.JavaLanguageVersion; -import org.gradle.jvm.toolchain.JavaToolchainSpec; +import org.gradle.jvm.toolchain.JavaToolchainService; /** * {@link Plugin} for customizing Gradle's toolchain support. * * @author Christoph Dreis + * @author Andy Wilkinson */ public class ToolchainPlugin implements Plugin { @@ -52,11 +48,7 @@ public class ToolchainPlugin implements Plugin { disableToolchainTasks(project); } else { - JavaToolchainSpec toolchainSpec = project.getExtensions() - .getByType(JavaPluginExtension.class) - .getToolchain(); - toolchainSpec.getLanguageVersion().set(toolchain.getJavaVersion()); - configureTestToolchain(project, toolchain); + configureTestToolchain(project, toolchain.getJavaVersion()); } } @@ -70,9 +62,11 @@ public class ToolchainPlugin implements Plugin { project.getTasks().withType(Test.class, (task) -> task.setEnabled(false)); } - private void configureTestToolchain(Project project, ToolchainExtension toolchain) { - List jvmArgs = new ArrayList<>(toolchain.getTestJvmArgs().getOrElse(Collections.emptyList())); - project.getTasks().withType(Test.class, (test) -> test.jvmArgs(jvmArgs)); + private void configureTestToolchain(Project project, JavaLanguageVersion toolchainVersion) { + JavaToolchainService javaToolchains = project.getExtensions().getByType(JavaToolchainService.class); + project.getTasks() + .withType(Test.class, (test) -> test.getJavaLauncher() + .set(javaToolchains.launcherFor((spec) -> spec.getLanguageVersion().set(toolchainVersion)))); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnAvailableEndpointTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnAvailableEndpointTests.java index 9636b5ac1f..9600fae146 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnAvailableEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnAvailableEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -324,6 +324,7 @@ class ConditionalOnAvailableEndpointTests { } + @SuppressWarnings({ "deprecation", "removal" }) @Endpoint(id = "disabledbutaccessible", enableByDefault = false) static class DisabledButAccessibleEndpoint { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/DisabledEndpoint.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/DisabledEndpoint.java index 694a6919a4..717ed5c24c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/DisabledEndpoint.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/DisabledEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import org.springframework.boot.configurationsample.Endpoint; * * @author Stephane Nicoll */ +@SuppressWarnings({ "deprecation", "removal" }) @Endpoint(id = "disabled", enableByDefault = false) public class DisabledEndpoint { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/SimpleEndpoint3.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/SimpleEndpoint3.java index 48c88f16f4..325e1560c3 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/SimpleEndpoint3.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/SimpleEndpoint3.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import org.springframework.boot.configurationsample.ReadOperation; * * @author Moritz Halbritter */ +@SuppressWarnings({ "deprecation", "removal" }) @Endpoint(id = "simple", enableByDefault = false) public class SimpleEndpoint3 { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/SpecificEndpoint.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/SpecificEndpoint.java index 49a003a71a..143c47ac05 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/SpecificEndpoint.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/endpoint/SpecificEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import org.springframework.lang.Nullable; * * @author Stephane Nicoll */ +@SuppressWarnings({ "deprecation", "removal" }) @WebEndpoint(id = "specific", enableByDefault = true) public class SpecificEndpoint { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/build.gradle index f225c0da7c..3554391b35 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/build.gradle @@ -84,6 +84,10 @@ sourceSets { } } +tasks.named("compileJava") { + options.compilerArgs -= ['-Werror'] +} + plugins.withType(EclipsePlugin) { eclipse { classpath.file { merger ->