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
This commit is contained in:
Alexey Tsvetkov
2018-06-22 00:42:33 +03:00
parent 03839f6861
commit e38cafb1a2
@@ -111,9 +111,10 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : 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<T : CommonCompilerArguments>() : AbstractKo
sourceRoots.log(this.name, logger)
val args = prepareCompilerArguments()
taskBuildDirectory.mkdirs()
callCompiler(args, sourceRoots, ChangedFiles(inputs))
}