From e38cafb1a29ce6f86257ea45e6f941e5f94f5082 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Fri, 22 Jun 2018 00:42:33 +0300 Subject: [PATCH] Don't create build directory for task in getter Since the property is public, it can be invoked from outside, possibly trough other properties. This can lead to unwanted side effects: we can create taskBuildDirectory, because some other task reads the property in parallel with 'clean' task in current project. That's exactly what happened when we referenced the property from 'GradleCompilerRunner#buildModulesInfo'. #KT-24938 fixed --- .../main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index 73859ffdfc2..fa942df1a9f 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -111,9 +111,10 @@ abstract class AbstractKotlinCompile() : AbstractKo cacheOnlyIfEnabledForKotlin() } + // avoid creating directory in getter: this can lead to failure in parallel build @get:LocalState internal val taskBuildDirectory: File - get() = File(File(project.buildDir, KOTLIN_BUILD_DIR_NAME), name).apply { mkdirs() } + get() = File(File(project.buildDir, KOTLIN_BUILD_DIR_NAME), name) // indicates that task should compile kotlin incrementally if possible // it's not possible when IncrementalTaskInputs#isIncremental returns false (i.e first build) @@ -249,6 +250,7 @@ abstract class AbstractKotlinCompile() : AbstractKo sourceRoots.log(this.name, logger) val args = prepareCompilerArguments() + taskBuildDirectory.mkdirs() callCompiler(args, sourceRoots, ChangedFiles(inputs)) }