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
This commit is contained in:
Andy Wilkinson
2026-07-31 13:16:06 +01:00
parent 811f3a225b
commit edc6fa3f28
@@ -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;
}