From edc6fa3f287f4310fb7a583ad1c14501d6422114 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 31 Jul 2026 13:16:06 +0100 Subject: [PATCH] Use temp directory when path of build directory is too long Some gRPC-related tests fail on Windows when the path becomes too long. The failure is somewhat cryptic: > protoc: stdout: . stderr: --grpc_out: protoc-gen-grpc: The system cannot find the path specified. The failure occurs when the path to the protoc-gen-grpc-java executable gets too long. Our Gradle plugin's tests configure TestKit to use a directory beneath spring-boot-gradle-plugin/build and this can result in the path being too long. This commit updates GradleBuild to use a directory beneath java.io.tmpdir when the tests are running on Windows and the absolute path of spring-boot-gradle-plugin/build 80 characters or more in length. Closes gh-51169 --- .../testsupport/gradle/testkit/GradleBuild.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test-support/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java b/test-support/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java index 996ea9b0faf..46cb31d2f5b 100644 --- a/test-support/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java +++ b/test-support/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java @@ -210,12 +210,25 @@ public class GradleBuild { } private File getTestKitDir() { - File build = this.buildOutput.getRootLocation(); - File testKitRoot = new File(build, "gradle-test-kit"); + File testKitRoot = getTestKitRoot(); String gradleVersion = (this.gradleVersion != null) ? this.gradleVersion : "default"; return new File(testKitRoot, gradleVersion).getAbsoluteFile(); } + private File getTestKitRoot() { + File build = this.buildOutput.getRootLocation(); + if (isWindows() && build.getAbsolutePath().length() >= 80) { + return new File(System.getProperty("java.io.tmpdir"), "gradle-test-kit"); + } + else { + return new File(build, "gradle-test-kit"); + } + } + + private boolean isWindows() { + return File.separatorChar == '\\'; + } + public File getProjectDir() { return this.projectDir; }