Skip to content

Commit ddc823d

Browse files
committed
fix: actually move testkit dir outside JUnit @tempdir
Commit 41002d9 intended to place the testkit directory in a separate OS temp location, but the change still used file(".testkit") which resolves to File(projectDir, ".testkit") — still inside the JUnit @tempdir. So closing the daemon is not enough because the Gradle daemon held file locks on the testkit caches when JUnit attempted cleanup.
1 parent 7578a30 commit ddc823d

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

buildSrc/src/test/kotlin/datadog/gradle/plugin/GradleFixture.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,27 @@ import org.gradle.testkit.runner.UnexpectedBuildResultException
66
import org.intellij.lang.annotations.Language
77
import org.w3c.dom.Document
88
import java.io.File
9+
import java.nio.file.Files
910
import javax.xml.parsers.DocumentBuilderFactory
1011

1112
/**
1213
* Base fixture for Gradle plugin integration tests.
1314
* Provides common functionality for setting up test projects and running Gradle builds.
1415
*/
1516
internal open class GradleFixture(protected val projectDir: File) {
16-
// Each fixture gets its own testkit dir so that a fresh daemon is started per
17-
// test — ensuring withEnvironment() vars (e.g. MAVEN_REPOSITORY_PROXY) are
18-
// correctly set on the daemon JVM and not inherited from a previously-started
19-
// daemon with a different test's environment.
20-
private val testKitDir: File by lazy { file(".testkit") }
17+
// Each fixture gets its own testkit dir in the system temp directory (NOT under
18+
// projectDir) so that JUnit's @TempDir cleanup doesn't race with daemon file locks.
19+
// See https://github.com/gradle/gradle/issues/12535
20+
// A fresh daemon is started per test — ensuring withEnvironment() vars (e.g.
21+
// MAVEN_REPOSITORY_PROXY) are correctly set on the daemon JVM and not inherited
22+
// from a previously-started daemon with a different test's environment.
23+
// A JVM shutdown hook removes the directory after all tests have run (and daemons
24+
// have been stopped), so file locks are guaranteed to be released by then.
25+
private val testKitDir: File by lazy {
26+
Files.createTempDirectory("gradle-testkit-").toFile().also { dir ->
27+
Runtime.getRuntime().addShutdownHook(Thread { dir.deleteRecursively() })
28+
}
29+
}
2130

2231
/**
2332
* Runs Gradle with the specified arguments.

0 commit comments

Comments
 (0)