Configure buildpack to use target Java version
With this commit, the Maven `spring-boot:build-image` goal and the Gradle `bootBuildImage` task will configure the OpenJDK buildpack to use the same JRE version as the project's target version, provided the buildpack Java version is not explicitly set in the build configuration. Fixes gh-20172
This commit is contained in:
@@ -20,6 +20,7 @@ import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gradle.api.JavaVersion;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.testfixtures.ProjectBuilder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -128,6 +129,27 @@ class BootBuildImageTests {
|
||||
.hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenJavaVersionIsSetInEnvironmentItIsIncludedInTheRequest() {
|
||||
this.buildImage.environment("BP_JAVA_VERSION", "from-env");
|
||||
this.buildImage.getTargetJavaVersion().set(JavaVersion.VERSION_1_8);
|
||||
assertThat(this.buildImage.createRequest().getEnv()).containsEntry("BP_JAVA_VERSION", "from-env").hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenTargetCompatibilityIsSetThenJavaVersionIsIncludedInTheRequest() {
|
||||
this.buildImage.getTargetJavaVersion().set(JavaVersion.VERSION_1_8);
|
||||
assertThat(this.buildImage.createRequest().getEnv()).containsEntry("BP_JAVA_VERSION", "8.*").hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenTargetCompatibilityIsSetThenJavaVersionIsAddedToEnvironment() {
|
||||
this.buildImage.environment("ALPHA", "a");
|
||||
this.buildImage.getTargetJavaVersion().set(JavaVersion.VERSION_11);
|
||||
assertThat(this.buildImage.createRequest().getEnv()).containsEntry("ALPHA", "a")
|
||||
.containsEntry("BP_JAVA_VERSION", "11.*").hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingDefaultConfigurationThenRequestHasVerboseLoggingDisabled() {
|
||||
assertThat(this.buildImage.createRequest().isVerboseLogging()).isFalse();
|
||||
|
||||
Reference in New Issue
Block a user