diff --git a/build-plugin/spring-boot-gradle-plugin/src/dockerTest/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java b/build-plugin/spring-boot-gradle-plugin/src/dockerTest/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java index db3268d4cb59..73373239b8d9 100644 --- a/build-plugin/spring-boot-gradle-plugin/src/dockerTest/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java +++ b/build-plugin/spring-boot-gradle-plugin/src/dockerTest/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java @@ -38,6 +38,7 @@ import org.junit.jupiter.api.TestTemplate; import org.junit.jupiter.api.condition.EnabledOnOs; import org.junit.jupiter.api.condition.OS; +import org.junit.jupiter.api.io.TempDir; import org.springframework.boot.buildpack.platform.docker.DockerApi; import org.springframework.boot.buildpack.platform.docker.DockerApi.ImageApi; @@ -62,6 +63,7 @@ * @author Andy Wilkinson * @author Scott Frederick * @author Rafael Ceccone + * @author Yanming Zhou */ @GradleCompatibility(configurationCache = true) @DisabledIfDockerUnavailable @@ -318,7 +320,7 @@ void buildsImageWithVolumeCaches() throws IOException { @TestTemplate @EnabledOnOs(value = OS.LINUX, disabledReason = "Works with Docker Engine on Linux but is not reliable with " + "Docker Desktop on other OSs") - void buildsImageWithBindCaches() throws IOException { + void buildsImageWithBindCaches(@TempDir Path tempDir) throws IOException { writeMainClass(); writeLongNameResource(); BuildResult result = this.gradleBuild.build("bootBuildImage"); @@ -328,9 +330,8 @@ void buildsImageWithBindCaches() throws IOException { assertThat(result.getOutput()).contains("---> Test Info buildpack building"); assertThat(result.getOutput()).contains("---> Test Info buildpack done"); removeImages(projectName); - String tempDir = System.getProperty("java.io.tmpdir"); - Path buildCachePath = Paths.get(tempDir, "junit-image-cache-" + projectName + "-build"); - Path launchCachePath = Paths.get(tempDir, "junit-image-cache-" + projectName + "-launch"); + Path buildCachePath = tempDir.resolve("junit-image-cache-" + projectName + "-build"); + Path launchCachePath = tempDir.resolve("junit-image-cache-" + projectName + "-launch"); assertThat(buildCachePath).exists().isDirectory(); assertThat(launchCachePath).exists().isDirectory(); cleanupCache(buildCachePath); diff --git a/build-plugin/spring-boot-maven-plugin/src/dockerTest/java/org/springframework/boot/maven/BuildImageTests.java b/build-plugin/spring-boot-maven-plugin/src/dockerTest/java/org/springframework/boot/maven/BuildImageTests.java index 582a651e45de..ecdb8182b8cb 100644 --- a/build-plugin/spring-boot-maven-plugin/src/dockerTest/java/org/springframework/boot/maven/BuildImageTests.java +++ b/build-plugin/spring-boot-maven-plugin/src/dockerTest/java/org/springframework/boot/maven/BuildImageTests.java @@ -29,6 +29,7 @@ import org.junit.jupiter.api.condition.EnabledOnOs; import org.junit.jupiter.api.condition.OS; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; import org.springframework.boot.buildpack.platform.docker.DockerApi; import org.springframework.boot.buildpack.platform.docker.DockerApi.ImageApi; @@ -49,6 +50,7 @@ * @author Stephane Nicoll * @author Scott Frederick * @author Rafael Ceccone + * @author Yanming Zhou */ @ExtendWith(MavenBuildExtension.class) @DisabledIfDockerUnavailable @@ -443,7 +445,7 @@ void whenBuildImageIsInvokedWithVolumeCaches(MavenBuild mavenBuild) { @TestTemplate @EnabledOnOs(value = OS.LINUX, disabledReason = "Works with Docker Engine on Linux but is not reliable with " + "Docker Desktop on other OSs") - void whenBuildImageIsInvokedWithBindCaches(MavenBuild mavenBuild) { + void whenBuildImageIsInvokedWithBindCaches(MavenBuild mavenBuild, @TempDir Path tempDir) { String testBuildId = randomString(); mavenBuild.project("dockerTest", "build-image-bind-caches") .goals("package") @@ -454,9 +456,8 @@ void whenBuildImageIsInvokedWithBindCaches(MavenBuild mavenBuild) { .contains("docker.io/library/build-image-bind-caches:0.0.1.BUILD-SNAPSHOT") .contains("Successfully built image"); removeImage("build-image-bind-caches", "0.0.1.BUILD-SNAPSHOT"); - String tempDir = System.getProperty("java.io.tmpdir"); - Path buildCachePath = Paths.get(tempDir, "junit-image-cache-" + testBuildId + "-build"); - Path launchCachePath = Paths.get(tempDir, "junit-image-cache-" + testBuildId + "-launch"); + Path buildCachePath = tempDir.resolve("junit-image-cache-" + testBuildId + "-build"); + Path launchCachePath = tempDir.resolve("junit-image-cache-" + testBuildId + "-launch"); assertThat(buildCachePath).exists().isDirectory(); assertThat(launchCachePath).exists().isDirectory(); cleanupCache(buildCachePath);