Kapt3: Make 'kaptTest' configuration extend 'kapt' (KT-10190)

This commit is contained in:
Yan Zhulanow
2016-12-08 19:29:12 +03:00
committed by Yan Zhulanow
parent 3f8accc2bf
commit 3ecac1bbd3
2 changed files with 21 additions and 7 deletions
@@ -45,9 +45,20 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
companion object {
private val VERBOSE_OPTION_NAME = "kapt.verbose"
val MAIN_KAPT_CONFIGURATION_NAME = "kapt"
fun getKaptConfigurationName(sourceSetName: String): String {
return if (sourceSetName != "main") "kapt${sourceSetName.capitalize()}" else "kapt"
return if (sourceSetName != "main")
"$MAIN_KAPT_CONFIGURATION_NAME${sourceSetName.capitalize()}"
else
MAIN_KAPT_CONFIGURATION_NAME
}
fun Project.findKaptConfiguration(sourceSetName: String): Configuration? {
return project.configurations.findByName(getKaptConfigurationName(sourceSetName))
}
fun findMainKaptConfiguration(project: Project) = project.findKaptConfiguration(MAIN_KAPT_CONFIGURATION_NAME)
}
private val kotlinToKaptTasksMap = mutableMapOf<KotlinCompile, KaptTask>()
@@ -64,10 +75,6 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
return dir
}
private fun Project.findKaptConfiguration(sourceSetName: String): Configuration? {
return project.configurations.findByName(getKaptConfigurationName(sourceSetName))
}
private class Kapt3SubpluginContext(
val project: Project,
val kotlinCompile: KotlinCompile,
@@ -575,8 +575,15 @@ private fun Project.createAptConfiguration(sourceSetName: String, kotlinPluginVe
val aptConfigurationName = Kapt3KotlinGradleSubplugin.getKaptConfigurationName(sourceSetName)
val aptConfiguration = configurations.create(aptConfigurationName)
val kotlinAnnotationProcessingDep = "org.jetbrains.kotlin:kotlin-annotation-processing:$kotlinPluginVersion"
aptConfiguration.dependencies.add(dependencies.create(kotlinAnnotationProcessingDep))
// Add base kotlin-annotation-processing artifact for the main kapt configuration,
// All other configurations (such as kaptTest) should extend the main one
if (aptConfiguration.name == Kapt3KotlinGradleSubplugin.MAIN_KAPT_CONFIGURATION_NAME) {
val kotlinAnnotationProcessingDep = "org.jetbrains.kotlin:kotlin-annotation-processing:$kotlinPluginVersion"
aptConfiguration.dependencies.add(dependencies.create(kotlinAnnotationProcessingDep))
} else {
Kapt3KotlinGradleSubplugin.findMainKaptConfiguration(this)?.let { aptConfiguration.extendsFrom(it) }
}
return aptConfiguration
}