Skip to content

Commit ffd0b43

Browse files
committed
Don't create the Kapt generate stubs output dir in lazy initializer
Creating a directory in the property getter interferes with Gradle cache outputs snapshotting, resulting in build cache being disabled for the task with the following info message: Caching disabled for task ':app:kaptGenerateStubsKotlin': Gradle does not know how file 'build/tmp/kapt3/incrementalData/main' was created (output property 'destinationDir'). Task output caching requires exclusive access to output paths to guarantee correctness. As Gradle automatically creates any @OutputDirectory, we don't need to create it at the task initialization phase.
1 parent cbb8bf2 commit ffd0b43

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/kapt/Kapt3KotlinGradleSubplugin.kt

+7-5
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,17 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
162162

163163
override fun isApplicable(project: Project, task: AbstractCompile) = task is KotlinCompile && Kapt3GradleSubplugin.isEnabled(project)
164164

165-
private fun Kapt3SubpluginContext.getKaptStubsDir() = createAndReturnTemporaryKaptDirectory("stubs")
165+
private fun Kapt3SubpluginContext.getKaptStubsDir() = temporaryKaptDirectory("stubs")
166166

167-
private fun Kapt3SubpluginContext.getKaptIncrementalDataDir() = createAndReturnTemporaryKaptDirectory("incrementalData")
167+
private fun Kapt3SubpluginContext.getKaptIncrementalDataDir() = temporaryKaptDirectory("incrementalData", doMkDirs = false)
168168

169-
private fun Kapt3SubpluginContext.getKaptIncrementalAnnotationProcessingCache() = createAndReturnTemporaryKaptDirectory("incApCache")
169+
private fun Kapt3SubpluginContext.getKaptIncrementalAnnotationProcessingCache() = temporaryKaptDirectory("incApCache")
170170

171-
private fun Kapt3SubpluginContext.createAndReturnTemporaryKaptDirectory(name: String): File {
171+
private fun Kapt3SubpluginContext.temporaryKaptDirectory(name: String, doMkDirs: Boolean = true): File {
172172
val dir = File(project.buildDir, "tmp/kapt3/$name/$sourceSetName")
173-
dir.mkdirs()
173+
if (doMkDirs) {
174+
dir.mkdirs()
175+
}
174176
return dir
175177
}
176178

0 commit comments

Comments
 (0)