Skip to content

Commit edc6fa3

Browse files
committed
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
1 parent 811f3a2 commit edc6fa3

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

  • test-support/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit

test-support/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,25 @@ private void copyTransformedScript(String script, File destination) throws IOExc
210210
}
211211

212212
private File getTestKitDir() {
213-
File build = this.buildOutput.getRootLocation();
214-
File testKitRoot = new File(build, "gradle-test-kit");
213+
File testKitRoot = getTestKitRoot();
215214
String gradleVersion = (this.gradleVersion != null) ? this.gradleVersion : "default";
216215
return new File(testKitRoot, gradleVersion).getAbsoluteFile();
217216
}
218217

218+
private File getTestKitRoot() {
219+
File build = this.buildOutput.getRootLocation();
220+
if (isWindows() && build.getAbsolutePath().length() >= 80) {
221+
return new File(System.getProperty("java.io.tmpdir"), "gradle-test-kit");
222+
}
223+
else {
224+
return new File(build, "gradle-test-kit");
225+
}
226+
}
227+
228+
private boolean isWindows() {
229+
return File.separatorChar == '\\';
230+
}
231+
219232
public File getProjectDir() {
220233
return this.projectDir;
221234
}

0 commit comments

Comments
 (0)