From c22e76632cca12cd6f0a57bf1f0662d649a54303 Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Mon, 24 Oct 2022 18:35:39 -0500 Subject: [PATCH] Add Build-Jdk-Spec to jar and war manifest when building with Gradle This commit adds a `Build-Jdk-Spec` attribute to the manifest in a jar or war file built with the Spring Boot Gradle plugin. This aligns the Gradle plugin's behavior with the default Maven plugin behavior. This removes the need to set a `BP_JVM_VERSION` environment variable when invoking Cloud Native Buildpacks, as the Paketo buildpacks will honor `Build-Jdk-Spec` in a jar or war manifest to determine the default JVM version. Fixes gh-32829 --- .../boot/gradle/plugin/JavaPluginAction.java | 4 ++-- .../boot/gradle/plugin/WarPluginAction.java | 7 ++++++ .../gradle/tasks/bundling/BootArchive.java | 10 +++++++++ .../tasks/bundling/BootArchiveSupport.java | 3 ++- .../gradle/tasks/bundling/BootBuildImage.java | 19 ---------------- .../boot/gradle/tasks/bundling/BootJar.java | 3 ++- .../boot/gradle/tasks/bundling/BootWar.java | 3 ++- .../AbstractBootArchiveIntegrationTests.java | 9 ++++++++ .../BootBuildImageIntegrationTests.java | 2 -- .../tasks/bundling/BootBuildImageTests.java | 22 ------------------- .../gradle/tasks/bundling/BootJarTests.java | 15 +++++++++++++ .../gradle/tasks/bundling/BootWarTests.java | 15 +++++++++++++ ....gradle => BootJarIntegrationTests.gradle} | 0 ....gradle => BootWarIntegrationTests.gradle} | 0 .../boot/maven/BuildImageTests.java | 8 +++---- .../boot/maven/BuildImageMojo.java | 14 ------------ ...aketoBuilderTests-bootDistZipJarApp.gradle | 1 + ...ketoBuilderTests-plainDistZipJarApp.gradle | 1 + .../PaketoBuilderTests-plainWarApp.gradle | 2 +- .../spring-boot-server-tests-app/build.gradle | 1 + 20 files changed, 72 insertions(+), 67 deletions(-) rename spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/{BootJarIntegrationTests-basicBuild.gradle => BootJarIntegrationTests.gradle} (100%) rename spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/{BootWarIntegrationTests-basicBuild.gradle => BootWarIntegrationTests.gradle} (100%) 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 c56a63c4f2..d6f0e22317 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 @@ -150,6 +150,8 @@ final class JavaPluginAction implements PluginApplicationAction { .provider(() -> (String) bootJar.getManifest().getAttributes().get("Start-Class")); bootJar.getMainClass().convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent() ? manifestStartClass : resolveMainClassName.get().readMainClassName())); + bootJar.getTargetJavaVersion() + .set(project.provider(() -> javaPluginExtension(project).getTargetCompatibility())); }); } @@ -158,8 +160,6 @@ 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.getArchiveFile().set(bootJar.get().getArchiveFile()); - buildImage.getTargetJavaVersion() - .set(project.provider(() -> javaPluginExtension(project).getTargetCompatibility())); }); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/WarPluginAction.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/WarPluginAction.java index 356535d9eb..b80d0b377d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/WarPluginAction.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/WarPluginAction.java @@ -25,6 +25,7 @@ import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.ConfigurationContainer; import org.gradle.api.file.FileCollection; import org.gradle.api.plugins.BasePlugin; +import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.plugins.WarPlugin; import org.gradle.api.provider.Provider; import org.gradle.api.tasks.SourceSet; @@ -90,6 +91,8 @@ class WarPluginAction implements PluginApplicationAction { bootWar.getMainClass() .convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent() ? manifestStartClass : resolveMainClassName.get().readMainClassName())); + bootWar.getTargetJavaVersion() + .set(project.provider(() -> javaPluginExtension(project).getTargetCompatibility())); }); bootWarProvider.map(War::getClasspath); return bootWarProvider; @@ -109,4 +112,8 @@ class WarPluginAction implements PluginApplicationAction { this.singlePublishedArtifact.addWarCandidate(bootWar); } + private JavaPluginExtension javaPluginExtension(Project project) { + return project.getExtensions().getByType(JavaPluginExtension.class); + } + } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchive.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchive.java index 02208681b2..1f6e5fa7dd 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchive.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchive.java @@ -17,6 +17,7 @@ package org.springframework.boot.gradle.tasks.bundling; import org.gradle.api.Action; +import org.gradle.api.JavaVersion; import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.file.FileCollection; @@ -110,4 +111,13 @@ public interface BootArchive extends Task { */ void setClasspath(FileCollection classpath); + /** + * Returns the target Java version of the project (e.g. as provided by the + * {@code targetCompatibility} build property). + * @return the target Java version + */ + @Input + @Optional + Property getTargetJavaVersion(); + } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchiveSupport.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchiveSupport.java index 36b7a73213..7335090fa5 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchiveSupport.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchiveSupport.java @@ -85,7 +85,7 @@ class BootArchiveSupport { } void configureManifest(Manifest manifest, String mainClass, String classes, String lib, String classPathIndex, - String layersIndex) { + String layersIndex, String jdkVersion) { Attributes attributes = manifest.getAttributes(); attributes.putIfAbsent("Main-Class", this.loaderMainClass); attributes.putIfAbsent("Start-Class", mainClass); @@ -98,6 +98,7 @@ class BootArchiveSupport { if (layersIndex != null) { attributes.putIfAbsent("Spring-Boot-Layers-Index", layersIndex); } + attributes.putIfAbsent("Build-Jdk-Spec", jdkVersion); } private String determineSpringBootVersion() { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java index 6480432029..7b02a85cc6 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java @@ -22,7 +22,6 @@ import java.util.Map; import org.gradle.api.Action; import org.gradle.api.DefaultTask; -import org.gradle.api.JavaVersion; import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.file.RegularFileProperty; @@ -66,8 +65,6 @@ import org.springframework.util.StringUtils; @DisableCachingByDefault public abstract class BootBuildImage extends DefaultTask { - private static final String BUILDPACK_JVM_VERSION_KEY = "BP_JVM_VERSION"; - private final Property pullPolicy; private final String projectName; @@ -107,15 +104,6 @@ public abstract class BootBuildImage extends DefaultTask { @PathSensitive(PathSensitivity.RELATIVE) public abstract RegularFileProperty getArchiveFile(); - /** - * Returns the target Java version of the project (e.g. as provided by the - * {@code targetCompatibility} build property). - * @return the target Java version - */ - @Input - @Optional - public abstract Property getTargetJavaVersion(); - /** * Returns the name of the image that will be built. When {@code null}, the name will * be derived from the {@link Project Project's} {@link Project#getName() name} and @@ -340,9 +328,6 @@ public abstract class BootBuildImage extends DefaultTask { if (environment != null && !environment.isEmpty()) { request = request.withEnv(environment); } - if (this.getTargetJavaVersion().isPresent() && !request.getEnv().containsKey(BUILDPACK_JVM_VERSION_KEY)) { - request = request.withEnv(BUILDPACK_JVM_VERSION_KEY, translateTargetJavaVersion()); - } return request; } @@ -401,8 +386,4 @@ public abstract class BootBuildImage extends DefaultTask { return request; } - private String translateTargetJavaVersion() { - return this.getTargetJavaVersion().get().getMajorVersion() + ".*"; - } - } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java index d3ce6e353a..cbbb07ec30 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java @@ -119,7 +119,8 @@ public abstract class BootJar extends Jar implements BootArchive { @Override public void copy() { this.support.configureManifest(getManifest(), getMainClass().get(), CLASSES_DIRECTORY, LIB_DIRECTORY, - CLASSPATH_INDEX, (isLayeredDisabled()) ? null : LAYERS_INDEX); + CLASSPATH_INDEX, (isLayeredDisabled()) ? null : LAYERS_INDEX, + this.getTargetJavaVersion().get().getMajorVersion()); super.copy(); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java index e622f08382..0ad92c183b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java @@ -94,7 +94,8 @@ public abstract class BootWar extends War implements BootArchive { @Override public void copy() { this.support.configureManifest(getManifest(), getMainClass().get(), CLASSES_DIRECTORY, LIB_DIRECTORY, - CLASSPATH_INDEX, (isLayeredDisabled()) ? null : LAYERS_INDEX); + CLASSPATH_INDEX, (isLayeredDisabled()) ? null : LAYERS_INDEX, + this.getTargetJavaVersion().get().getMajorVersion()); super.copy(); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java index b112b481d1..8f39cb4148 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java @@ -478,6 +478,15 @@ abstract class AbstractBootArchiveIntegrationTests { } } + @TestTemplate + void javaVersionIsSetInManifest() throws IOException { + BuildResult result = this.gradleBuild.build(this.taskName); + assertThat(result.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS); + try (JarFile jarFile = new JarFile(new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0])) { + assertThat(jarFile.getManifest().getMainAttributes().getValue("Build-Jdk-Spec")).isNotEmpty(); + } + } + private void copyMainClassApplication() throws IOException { copyApplication("main"); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java index 704b9ba4c8..4d691b7444 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java @@ -73,7 +73,6 @@ class BootBuildImageIntegrationTests { assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); assertThat(result.getOutput()).contains("docker.io/library/" + projectName); assertThat(result.getOutput()).contains("---> Test Info buildpack building"); - assertThat(result.getOutput()).contains("env: BP_JVM_VERSION=8.*"); assertThat(result.getOutput()).contains("Network status: HTTP/2 200"); assertThat(result.getOutput()).contains("---> Test Info buildpack done"); removeImages(projectName); @@ -88,7 +87,6 @@ class BootBuildImageIntegrationTests { assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); assertThat(result.getOutput()).contains("docker.io/library/" + projectName); assertThat(result.getOutput()).contains("---> Test Info buildpack building"); - assertThat(result.getOutput()).contains("env: BP_JVM_VERSION=8.*"); assertThat(result.getOutput()).contains("---> Test Info buildpack done"); File buildLibs = new File(this.gradleBuild.getProjectDir(), "build/libs"); assertThat(buildLibs.listFiles()) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageTests.java index 058e62957f..634d80b8be 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageTests.java @@ -21,7 +21,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import org.gradle.api.JavaVersion; import org.gradle.api.Project; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -139,27 +138,6 @@ class BootBuildImageTests { .hasSize(2); } - @Test - void whenJavaVersionIsSetInEnvironmentItIsIncludedInTheRequest() { - this.buildImage.getEnvironment().put("BP_JVM_VERSION", "from-env"); - this.buildImage.getTargetJavaVersion().set(JavaVersion.VERSION_1_8); - assertThat(this.buildImage.createRequest().getEnv()).containsEntry("BP_JVM_VERSION", "from-env").hasSize(1); - } - - @Test - void whenTargetCompatibilityIsSetThenJavaVersionIsIncludedInTheRequest() { - this.buildImage.getTargetJavaVersion().set(JavaVersion.VERSION_1_8); - assertThat(this.buildImage.createRequest().getEnv()).containsEntry("BP_JVM_VERSION", "8.*").hasSize(1); - } - - @Test - void whenTargetCompatibilityIsSetThenJavaVersionIsAddedToEnvironment() { - this.buildImage.getEnvironment().put("ALPHA", "a"); - this.buildImage.getTargetJavaVersion().set(JavaVersion.VERSION_11); - assertThat(this.buildImage.createRequest().getEnv()).containsEntry("ALPHA", "a") - .containsEntry("BP_JVM_VERSION", "11.*").hasSize(2); - } - @Test void whenUsingDefaultConfigurationThenRequestHasVerboseLoggingDisabled() { assertThat(this.buildImage.createRequest().isVerboseLogging()).isFalse(); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java index ee8efd74cc..a14dd78893 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java @@ -22,7 +22,9 @@ import java.util.jar.JarFile; import java.util.zip.ZipEntry; import org.gradle.api.Action; +import org.gradle.api.JavaVersion; import org.gradle.api.artifacts.Configuration; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.boot.testsupport.classpath.ClassPathExclusions; @@ -45,6 +47,11 @@ class BootJarTests extends AbstractBootArchiveTests { "BOOT-INF/"); } + @BeforeEach + void setUp() { + this.getTask().getTargetJavaVersion().set(JavaVersion.VERSION_17); + } + @Test void contentCanBeAddedToBootInfUsingCopySpecFromGetter() throws IOException { BootJar bootJar = getTask(); @@ -194,6 +201,14 @@ class BootJarTests extends AbstractBootArchiveTests { } } + @Test + void javaVersionIsWrittenToManifest() throws IOException { + try (JarFile jarFile = new JarFile(createPopulatedJar())) { + assertThat(jarFile.getManifest().getMainAttributes().getValue("Build-Jdk-Spec")) + .isEqualTo(JavaVersion.VERSION_17.getMajorVersion()); + } + } + @Override void applyLayered(Action action) { getTask().layered(action); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootWarTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootWarTests.java index 3d21484834..8d1500460c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootWarTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootWarTests.java @@ -21,7 +21,9 @@ import java.io.IOException; import java.util.jar.JarFile; import org.gradle.api.Action; +import org.gradle.api.JavaVersion; import org.gradle.api.artifacts.Configuration; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.boot.testsupport.classpath.ClassPathExclusions; @@ -42,6 +44,11 @@ class BootWarTests extends AbstractBootArchiveTests { "WEB-INF/"); } + @BeforeEach + void setUp() { + this.getTask().getTargetJavaVersion().set(JavaVersion.VERSION_17); + } + @Test void providedClasspathJarsArePackagedInWebInfLibProvided() throws IOException { getTask().getMainClass().set("com.example.Main"); @@ -137,6 +144,14 @@ class BootWarTests extends AbstractBootArchiveTests { } } + @Test + void javaVersionIsWrittenToManifest() throws IOException { + try (JarFile jarFile = new JarFile(createPopulatedJar())) { + assertThat(jarFile.getManifest().getMainAttributes().getValue("Build-Jdk-Spec")) + .isEqualTo(JavaVersion.VERSION_17.getMajorVersion()); + } + } + @Override protected void executeTask() { getTask().copy(); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-basicBuild.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests.gradle similarity index 100% rename from spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-basicBuild.gradle rename to spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests.gradle diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests-basicBuild.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests.gradle similarity index 100% rename from spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests-basicBuild.gradle rename to spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootWarIntegrationTests.gradle diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildImageTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildImageTests.java index f38272b00f..ba1be427e5 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildImageTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildImageTests.java @@ -58,8 +58,8 @@ class BuildImageTests extends AbstractArchiveIntegrationTests { assertThat(original).doesNotExist(); assertThat(buildLog(project)).contains("Building image") .contains("docker.io/library/build-image:0.0.1.BUILD-SNAPSHOT") - .contains("---> Test Info buildpack building").contains("env: BP_JVM_VERSION=8.*") - .contains("---> Test Info buildpack done").contains("Successfully built image"); + .contains("---> Test Info buildpack building").contains("---> Test Info buildpack done") + .contains("Successfully built image"); removeImage("build-image", "0.0.1.BUILD-SNAPSHOT"); }); } @@ -75,8 +75,8 @@ class BuildImageTests extends AbstractArchiveIntegrationTests { assertThat(classifier).doesNotExist(); assertThat(buildLog(project)).contains("Building image") .contains("docker.io/library/build-image-classifier:0.0.1.BUILD-SNAPSHOT") - .contains("---> Test Info buildpack building").contains("env: BP_JVM_VERSION=8.*") - .contains("---> Test Info buildpack done").contains("Successfully built image"); + .contains("---> Test Info buildpack building").contains("---> Test Info buildpack done") + .contains("Successfully built image"); removeImage("build-image-classifier", "0.0.1.BUILD-SNAPSHOT"); }); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildImageMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildImageMojo.java index c70ef3e8d4..6b6da97a53 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildImageMojo.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildImageMojo.java @@ -68,8 +68,6 @@ import org.springframework.util.StringUtils; @Execute(phase = LifecyclePhase.PACKAGE) public class BuildImageMojo extends AbstractPackagerMojo { - private static final String BUILDPACK_JVM_VERSION_KEY = "BP_JVM_VERSION"; - static { System.setProperty("org.slf4j.simpleLogger.log.org.apache.http.wire", "ERROR"); } @@ -293,22 +291,10 @@ public class BuildImageMojo extends AbstractPackagerMojo { } private BuildRequest customize(BuildRequest request) { - request = customizeEnvironment(request); request = customizeCreator(request); return request; } - private BuildRequest customizeEnvironment(BuildRequest request) { - if (!request.getEnv().containsKey(BUILDPACK_JVM_VERSION_KEY)) { - JavaCompilerPluginConfiguration compilerConfiguration = new JavaCompilerPluginConfiguration(this.project); - String targetJavaVersion = compilerConfiguration.getTargetMajorVersion(); - if (StringUtils.hasText(targetJavaVersion)) { - return request.withEnv(BUILDPACK_JVM_VERSION_KEY, targetJavaVersion + ".*"); - } - } - return request; - } - private BuildRequest customizeCreator(BuildRequest request) { String springBootVersion = VersionExtractor.forClass(BuildImageMojo.class); if (StringUtils.hasText(springBootVersion)) { diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-bootDistZipJarApp.gradle b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-bootDistZipJarApp.gradle index 0c76d495d7..882dc4b51f 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-bootDistZipJarApp.gradle +++ b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-bootDistZipJarApp.gradle @@ -38,4 +38,5 @@ application { bootBuildImage { archiveFile = bootDistZip.archiveFile + environment = ['BP_JVM_VERSION': project.targetCompatibility.getMajorVersion()] } \ No newline at end of file diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainDistZipJarApp.gradle b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainDistZipJarApp.gradle index 797ccb8829..6a69d79634 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainDistZipJarApp.gradle +++ b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainDistZipJarApp.gradle @@ -38,4 +38,5 @@ application { bootBuildImage { archiveFile = distZip.archiveFile + environment = ['BP_JVM_VERSION': project.targetCompatibility.getMajorVersion()] } \ No newline at end of file diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainWarApp.gradle b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainWarApp.gradle index b295c94a7d..e7e8548705 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainWarApp.gradle +++ b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainWarApp.gradle @@ -31,5 +31,5 @@ war { bootBuildImage { archiveFile = war.archiveFile - environment = ['BP_TOMCAT_VERSION': '10.*'] + environment = ['BP_JVM_VERSION': project.targetCompatibility.getMajorVersion(), 'BP_TOMCAT_VERSION': '10.*'] } diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/build.gradle b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/build.gradle index 2b8a58f947..0b0dd61b08 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/build.gradle +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/build.gradle @@ -72,6 +72,7 @@ def boolean isWindows() { task.mainClass = "com.example.ResourceHandlingApplication" task.classpath = sourceSets.main.runtimeClasspath.plus(configurations.getByName(container)) task.classifier = container + task.targetJavaVersion = project.getTargetCompatibility() } tasks.register("${container}BootJar", BootJar, configurer) tasks.register("${container}BootWar", BootWar, configurer)