Kapt: Attach generated Kotlin sources in 'compilation' mode (KT-32535)

This commit is contained in:
Yan Zhulanow
2019-07-23 20:42:52 +09:00
parent 1c63d3aa2f
commit ccff347ffc
11 changed files with 168 additions and 7 deletions
@@ -65,7 +65,8 @@ import java.io.StringWriter
import java.io.Writer
import java.net.URLClassLoader
import javax.annotation.processing.Processor
import com.sun.tools.javac.util.List as JavacList
private const val KAPT_KOTLIN_GENERATED_OPTION_NAME = "kapt.kotlin.generated"
class ClasspathBasedKapt3Extension(
options: KaptOptions,
@@ -204,15 +205,21 @@ abstract class AbstractKapt3Extension(
return if (options.mode != WITH_COMPILATION) {
doNotGenerateCode()
} else {
AnalysisResult.RetryWithAdditionalJavaRoots(
AnalysisResult.RetryWithAdditionalRoots(
bindingTrace.bindingContext,
module,
listOf(options.sourcesOutputDir),
listOfNotNull(options.sourcesOutputDir, getKotlinGeneratedSourcesDirectory()),
addToEnvironment = true
)
}
}
private fun getKotlinGeneratedSourcesDirectory(): File? {
val value = options.processingOptions[KAPT_KOTLIN_GENERATED_OPTION_NAME] ?: return null
return File(value).takeIf { it.exists() }
}
private fun runAnnotationProcessing(kaptContext: KaptContext, processors: LoadedProcessors) {
if (!options.mode.runAnnotationProcessing) return