From c45ad6ce83096454152a4f325d1fa90705c7e828 Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Fri, 22 Sep 2023 13:38:37 -0500 Subject: [PATCH] Use actual Java version in build image integration tests See gh-37453 --- .../BootBuildImageIntegrationTests.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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 7aacc87d4f..08a7e4e85a 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 @@ -75,7 +75,7 @@ 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("env: BP_JVM_VERSION=" + javaMajorVersion() + ".*"); assertThat(result.getOutput()).contains("Network status: HTTP/2 200"); assertThat(result.getOutput()).contains("---> Test Info buildpack done"); removeImages(projectName); @@ -91,7 +91,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()) @@ -479,4 +478,18 @@ class BootBuildImageIntegrationTests { } } + private String javaMajorVersion() { + String javaVersion = System.getProperty("java.version"); + if (javaVersion.startsWith("1.")) { + return javaVersion.substring(2, 3); + } + else { + int firstDotIndex = javaVersion.indexOf("."); + if (firstDotIndex != -1) { + return javaVersion.substring(0, firstDotIndex); + } + } + return javaVersion; + } + }