KT-31127: add only generated Java sources to JavaCompile inputs

This commit changes how generated sources are added to the Gradle JavaCompile
task. Previously, directory was added to sources which caused issues with
annotation processors that only generate Kotlin sources. I.e. JavaCompile task
was executed but no java sources existed.

Now, only generated Java sources are added to the JavaCompile task. This
means that if only Kotlin sources are generated JavaCompile task will be
skipped.

Fixes: KT-31127
Test: Kapt3IT.testKotlinProcessorUsingFiler
This commit is contained in:
Ivan Gavrilovic
2019-05-28 17:19:26 +01:00
committed by Yan Zhulanow
parent 55ba985cd2
commit 695f202e46
6 changed files with 86 additions and 5 deletions
@@ -266,8 +266,6 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
pluginOptions += SubpluginOption("aptMode", aptMode)
disableAnnotationProcessingInJavaTask()
javaCompile?.source(generatedFilesDir)
pluginOptions += FilesSubpluginOption("sources", listOf(generatedFilesDir))
pluginOptions += FilesSubpluginOption("classes", listOf(getKaptGeneratedClassesDir(project, sourceSetName)))
@@ -527,7 +525,9 @@ private val artifactType = Attribute.of("artifactType", String::class.java)
internal fun registerGeneratedJavaSource(kaptTask: KaptTask, javaTask: AbstractCompile) {
javaTask.source(kaptTask.destinationDir)
val generatedJavaSources = javaTask.project.fileTree(kaptTask.destinationDir)
generatedJavaSources.include("**/*.java")
javaTask.source(generatedJavaSources)
}
internal fun Configuration.getNamedDependencies(): List<Dependency> = allDependencies.filter { it.group != null && it.name != null }