From ef5fbb066911dc33759d013ff73d0f4830e18f99 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 29 Apr 2021 11:32:31 +0100 Subject: [PATCH] Configure bootBuildImage's targetJavaVersion using a provider Previously, the targetJavaVersion property of bootBuildImage was set using the project's target compatibility directly. This meant that property's value would reflect the configured target compatibility at the time of the task's creation and any subsequent changes to the target compatibility would be missed. This commit updates the registration of the bootBuildImage task to set the value of the targetJavaVersion property using a provider. This indirection means that the project's target compatibility isn't read until the value of the targetJavaVersion is read, allowing any changes to the target compatibility to be picked up even if they're made after the bootBuildImage task has been created. Fixes gh-26297 --- .../springframework/boot/gradle/plugin/JavaPluginAction.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java index 6583e87557..4fcc571c3c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java @@ -119,7 +119,8 @@ final class JavaPluginAction implements PluginApplicationAction { buildImage.setDescription("Builds an OCI image of the application using the output of the bootJar task"); buildImage.setGroup(BasePlugin.BUILD_GROUP); buildImage.getJar().set(bootJar.get().getArchiveFile()); - buildImage.getTargetJavaVersion().set(javaPluginConvention(project).getTargetCompatibility()); + buildImage.getTargetJavaVersion() + .set(project.provider(() -> javaPluginConvention(project).getTargetCompatibility())); }); }