KT-45168: Avoid generating stubs for generated Kotlin sources
Filter out Kotlin sources coming from KAPT-generated dirs. Some annotation processors e.g Moshi, generate Kotlin sources, and when generating stubs in non-incremental runs, stub generation must ignore those sources. This fixes #KT-45168. Test: Kapt3IT
This commit is contained in:
committed by
nataliya.valtman
parent
34274dd032
commit
08446e2371
+1
-1
@@ -563,7 +563,7 @@ class Kapt3GradleSubplugin @Inject internal constructor(private val registry: To
|
||||
kaptTask.stubsDir = getKaptStubsDir()
|
||||
kaptTask.setDestinationDir { getKaptIncrementalDataDir() }
|
||||
kaptTask.mapClasspath { kaptTask.kotlinCompileTask.classpath }
|
||||
kaptTask.generatedSourcesDir = sourcesOutputDir
|
||||
kaptTask.generatedSourcesDirs = listOf(sourcesOutputDir, kotlinSourcesOutputDir)
|
||||
|
||||
kaptTask.kaptClasspathConfigurations = kaptClasspathConfigurations
|
||||
|
||||
|
||||
+3
-3
@@ -45,7 +45,7 @@ open class KaptGenerateStubsTask : KotlinCompile() {
|
||||
lateinit var stubsDir: File
|
||||
|
||||
@get:Internal
|
||||
lateinit var generatedSourcesDir: File
|
||||
lateinit var generatedSourcesDirs: List<File>
|
||||
|
||||
@get:Classpath
|
||||
@get:InputFiles
|
||||
@@ -83,7 +83,7 @@ open class KaptGenerateStubsTask : KotlinCompile() {
|
||||
private fun isSourceRootAllowed(source: File): Boolean =
|
||||
!destinationDir.isParentOf(source) &&
|
||||
!stubsDir.isParentOf(source) &&
|
||||
!generatedSourcesDir.isParentOf(source)
|
||||
generatedSourcesDirs.none { it.isParentOf(source) }
|
||||
|
||||
private val compileKotlinArgumentsContributor by project.provider {
|
||||
kotlinCompileTask.compilerArgumentsContributor
|
||||
@@ -106,7 +106,7 @@ open class KaptGenerateStubsTask : KotlinCompile() {
|
||||
private val sourceRoots by project.provider {
|
||||
kotlinCompileTask.getSourceRoots().let {
|
||||
val javaSourceRoots = it.javaSourceRoots.filterTo(HashSet()) { isSourceRootAllowed(it) }
|
||||
val kotlinSourceFiles = it.kotlinSourceFiles
|
||||
val kotlinSourceFiles = it.kotlinSourceFiles.filterTo(ArrayList()) { isSourceRootAllowed(it) }
|
||||
SourceRoots.ForJvm(kotlinSourceFiles, javaSourceRoots)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user