From 464b302655fd7d7f5cacd28d6d70b75923b0c17a Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 25 Jan 2021 21:33:45 -0800 Subject: [PATCH] Set withTestKitDir per Gradle version Attempt to fix cache locking issues by setting a unique `withTestKitDir` directory for each tested Gradle version. Closes gh-24993 --- .../boot/gradle/testkit/GradleBuild.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java index 41522140acf..b8c5b29cf03 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/GradleBuild.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -163,6 +163,7 @@ public class GradleBuild { if (this.gradleVersion != null) { gradleRunner.withGradleVersion(this.gradleVersion); } + gradleRunner.withTestKitDir(getTestKitDir()); List allArguments = new ArrayList<>(); allArguments.add("-PbootVersion=" + getBootVersion()); allArguments.add("--stacktrace"); @@ -172,6 +173,13 @@ public class GradleBuild { return gradleRunner.withArguments(allArguments); } + private File getTestKitDir() { + File temp = new File(System.getProperty("java.io.tmpdir")); + String username = System.getProperty("user.name"); + String gradleVersion = (this.gradleVersion != null) ? this.gradleVersion : "default"; + return new File(temp, ".gradle-test-kit-" + username + "-" + getBootVersion() + "-" + gradleVersion); + } + public File getProjectDir() { return this.projectDir; }