From e1f9116684d23cb7be0a5e1e2237a20aebfe3af8 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 14 Oct 2025 14:37:57 +0200 Subject: [PATCH] Raise GraalVM baseline to 25 This also removes the 'requiredVersion' setting from the native-maven-plugin configuration, as this is deprecated in the native build tools. Close gh-47433 --- .../modules/gradle-plugin/pages/reacting.adoc | 1 - .../boot/SpringApplication.java | 28 +++++++++++++++++++ .../developing-your-first-application.adoc | 10 +++---- gradle.properties | 2 +- .../spring-boot-starter-parent/build.gradle | 2 -- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/pages/reacting.adoc b/build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/pages/reacting.adoc index e1e2e2b2959..d4dc98cccde 100644 --- a/build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/pages/reacting.adoc +++ b/build-plugin/spring-boot-gradle-plugin/src/docs/antora/modules/gradle-plugin/pages/reacting.adoc @@ -87,7 +87,6 @@ When the {url-native-build-tools-docs-gradle-plugin}[GraalVM Native Image plugin . Adds the output of the `aot` source set to the classpath of the `main` GraalVM native binary. . Adds the output of the `aotTest` source set to the classpath of the `test` GraalVM native binary. . Configures the GraalVM extension to disable Toolchain detection. -. Configures each GraalVM native binary to require GraalVM 22.3 or later. . Configures the `bootJar` task to include the reachability metadata produced by the `collectReachabilityMetadata` task in its jar. . Configures the `bootJar` task to add the `Spring-Boot-Native-Processed: true` manifest entry. diff --git a/core/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/core/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index d4062fa4e68..d0bb59a1bb8 100644 --- a/core/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/core/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -66,6 +66,7 @@ import org.springframework.boot.context.properties.bind.Binder; import org.springframework.boot.context.properties.source.ConfigurationPropertySources; import org.springframework.boot.convert.ApplicationConversionService; import org.springframework.boot.env.DefaultPropertiesPropertySource; +import org.springframework.boot.system.JavaVersion; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ApplicationListener; @@ -418,6 +419,9 @@ public class SpringApplication { } private void addAotGeneratedInitializerIfNecessary(List> initializers) { + if (NativeDetector.inNativeImage()) { + checkNativeImageVersion(); + } if (AotDetector.useGeneratedArtifacts()) { List> aotInitializers = new ArrayList<>( initializers.stream().filter(AotApplicationContextInitializer.class::isInstance).toList()); @@ -434,6 +438,15 @@ public class SpringApplication { } } + private void checkNativeImageVersion() { + JavaVersion minRequiredJavaVersion = JavaVersion.TWENTY_FIVE; + if (JavaVersion.getJavaVersion().isOlderThan(minRequiredJavaVersion)) { + throw new NativeImageRequirementsNotMetException( + "Native Image requirements not met, please upgrade it. Native Image must support at least Java %s" + .formatted(minRequiredJavaVersion)); + } + } + private void refreshContext(ConfigurableApplicationContext context) { if (this.properties.isRegisterShutdownHook()) { shutdownHook.registerApplicationContext(context); @@ -1645,6 +1658,21 @@ public class SpringApplication { } + /** + * Exception which is thrown if GraalVM's native-image requirements aren't met. + */ + private static final class NativeImageRequirementsNotMetException extends RuntimeException { + + /** + * Creates a new {@link NativeImageRequirementsNotMetException} instance. + * @param message the message + */ + private NativeImageRequirementsNotMetException(String message) { + super(message); + } + + } + /** * {@link SpringApplicationHook} decorator that ensures the hook is only used once. */ diff --git a/documentation/spring-boot-docs/src/docs/antora/modules/how-to/pages/native-image/developing-your-first-application.adoc b/documentation/spring-boot-docs/src/docs/antora/modules/how-to/pages/native-image/developing-your-first-application.adoc index dbe6aa96a08..34ba0dbf822 100644 --- a/documentation/spring-boot-docs/src/docs/antora/modules/how-to/pages/native-image/developing-your-first-application.adoc +++ b/documentation/spring-boot-docs/src/docs/antora/modules/how-to/pages/native-image/developing-your-first-application.adoc @@ -175,8 +175,8 @@ Get SDKMAN! from https://sdkman.io and install the Liberica GraalVM distribution [source,shell,subs="verbatim,attributes"] ---- -$ sdk install java {version-graal}.r17-nik -$ sdk use java {version-graal}.r17-nik +$ sdk install java 25.r25-nik +$ sdk use java 25.r25-nik ---- Verify that the correct version has been configured by checking the output of `java -version`: @@ -184,9 +184,9 @@ Verify that the correct version has been configured by checking the output of `j [source,shell,subs="verbatim,attributes"] ---- $ java -version -openjdk version "17.0.5" 2022-10-18 LTS -OpenJDK Runtime Environment GraalVM 22.3.0 (build 17.0.5+8-LTS) -OpenJDK 64-Bit Server VM GraalVM 22.3.0 (build 17.0.5+8-LTS, mixed mode) +openjdk version "25" 2025-09-16 LTS +OpenJDK Runtime Environment Liberica-NIK-25.0.0-1 (build 25+37-LTS) +OpenJDK 64-Bit Server VM Liberica-NIK-25.0.0-1 (build 25+37-LTS, mixed mode, sharing) ---- diff --git a/gradle.properties b/gradle.properties index 198789defd7..99802c8d2ef 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8 assertjVersion=3.27.6 checkstyleToolVersion=10.12.4 commonsCodecVersion=1.19.0 -graalVersion=22.3 +graalVersion=25 hamcrestVersion=3.0 jackson2Version=2.20.0 jacksonVersion=3.0.0 diff --git a/starter/spring-boot-starter-parent/build.gradle b/starter/spring-boot-starter-parent/build.gradle index e26b5028588..986865eadad 100644 --- a/starter/spring-boot-starter-parent/build.gradle +++ b/starter/spring-boot-starter-parent/build.gradle @@ -297,7 +297,6 @@ publishing.publications.withType(MavenPublication) { delegate.artifactId('native-maven-plugin') configuration { delegate.classesDirectory('${project.build.outputDirectory}') - delegate.requiredVersion('22.3') exclusions { exclusion { delegate.groupId('org.springframework.boot') @@ -347,7 +346,6 @@ publishing.publications.withType(MavenPublication) { delegate.artifactId('native-maven-plugin') configuration { delegate.classesDirectory('${project.build.outputDirectory}') - delegate.requiredVersion('22.3') exclusions { exclusion { delegate.groupId('org.springframework.boot')