Skip to content

Commit bb2e04b

Browse files
committed
Use absolute path for temporary directory in tests (#52228)
We explicitly set the path for the temporary directory to use in test tasks, but today this path is a relative path, relative to the current working directory of the test task. The fact that we are using a relative path here appears to be legacy, simply leftover from the days of the Maven build. An absolute path is preferred here, since it's explicit and we do not have to rely on everyone resolving the path properly relative to the working directory.
1 parent 6ed3311 commit bb2e04b

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,17 +732,14 @@ class BuildPlugin implements Plugin<Project> {
732732
test.jvmArgs '-ea', '-esa'
733733
}
734734

735-
// we use './temp' since this is per JVM and tests are forbidden from writing to CWD
736735
test.systemProperties 'gradle.dist.lib': new File(project.class.location.toURI()).parent,
737-
'java.io.tmpdir': './temp',
738736
'java.awt.headless': 'true',
739737
'tests.gradle': 'true',
740738
'tests.artifact': project.name,
741739
'tests.task': test.path,
742740
'tests.security.manager': 'true',
743741
'jna.nosys': 'true'
744742

745-
746743
// ignore changing test seed when build is passed -Dignore.tests.seed for cacheability experimentation
747744
if (System.getProperty('ignore.tests.seed') != null) {
748745
nonInputProperties.systemProperty('tests.seed', BuildParams.testSeed)
@@ -753,6 +750,8 @@ class BuildPlugin implements Plugin<Project> {
753750
// don't track these as inputs since they contain absolute paths and break cache relocatability
754751
nonInputProperties.systemProperty('gradle.worker.jar', "${project.gradle.getGradleUserHomeDir()}/caches/${project.gradle.gradleVersion}/workerMain/gradle-worker.jar")
755752
nonInputProperties.systemProperty('gradle.user.home', project.gradle.getGradleUserHomeDir())
753+
// we use 'temp' relative to CWD since this is per JVM and tests are forbidden from writing to CWD
754+
nonInputProperties.systemProperty('java.io.tmpdir', test.workingDir.toPath().resolve('temp'))
756755

757756
nonInputProperties.systemProperty('compiler.java', "${-> BuildParams.compilerJavaVersion.majorVersion}")
758757

0 commit comments

Comments
 (0)