From 4787ae113960f3af2a22d616ff50f10083a6538f Mon Sep 17 00:00:00 2001 From: Ting-Yuan Huang Date: Thu, 5 Oct 2023 12:30:05 -0700 Subject: [PATCH] Add generated source set with new KGP API KotlinCompilation.source() is deprecated. (cherry picked from commit fbeec1f5e5eeb74d16096f3fa8f983d2269d0ec1) --- .../com/google/devtools/ksp/gradle/KspSubplugin.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt index df194590db..f0c0365b54 100644 --- a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt +++ b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KspSubplugin.kt @@ -555,7 +555,15 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool // No else; The cases should be exhaustive } kspGeneratedSourceSet.kotlin.srcDir(project.files(kotlinOutputDir, javaOutputDir).builtBy(kspTaskProvider)) - kotlinCompilation.source(kspGeneratedSourceSet) + if (kotlinCompilation is KotlinCommonCompilation) { + // Do not make common source sets depend on generated source sets. + // They will be observed by downstreams and confuse processors. + kotlinCompileProvider.configure { + it.source(kspGeneratedSourceSet.kotlin) + } + } else { + kotlinCompilation.defaultSourceSet.dependsOn(kspGeneratedSourceSet) + } kotlinCompileProvider.configure { kotlinCompile -> when (kotlinCompile) { is AbstractKotlinCompile<*> -> kotlinCompile.libraries.from(project.files(classOutputDir))