Skip to content

Commit

Permalink
Disable KSP in KAPT tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
ting-yuan committed Oct 8, 2020
1 parent 3077421 commit 172f7cc
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.config.CompilerConfigurationKey
import com.google.devtools.ksp.processing.impl.MessageCollectorBasedKSPLogger
import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
import java.io.File
import org.jetbrains.kotlin.config.JVMConfigurationKeys

private val KSP_OPTIONS = CompilerConfigurationKey.create<KspOptions.Builder>("Ksp options")

Expand Down Expand Up @@ -64,6 +65,17 @@ class KotlinSymbolProcessingCommandLineProcessor : CommandLineProcessor {

class KotlinSymbolProcessingComponentRegistrar : ComponentRegistrar {
override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
// Don't bother with KAPT tasks.
// There is no way to pass KSP options to compileKotlin only. Have to workaround here.
val outputDir = configuration[JVMConfigurationKeys.OUTPUT_DIRECTORY]
val kaptOutputDirs = listOf(
listOf("tmp", "kapt3", "stubs"),
listOf("tmp", "kapt3", "incrementalData"),
listOf("tmp", "kapt3", "incApCache")
).map { File(it.joinToString(File.separator)) }
if (kaptOutputDirs.any { outputDir?.parentFile?.endsWith(it) == true })
return

val contentRoots = configuration[CLIConfigurationKeys.CONTENT_ROOTS] ?: emptyList()
val options = configuration[KSP_OPTIONS]?.apply {
javaSourceRoots.addAll(contentRoots.filterIsInstance<JavaSourceRoot>().map { it.file })
Expand Down

0 comments on commit 172f7cc

Please sign in to comment.