Kapt3: Make 'kaptTest' configuration extend 'kapt' (KT-10190)
This commit is contained in:
committed by
Yan Zhulanow
parent
3f8accc2bf
commit
3ecac1bbd3
+12
-5
@@ -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,
|
||||
|
||||
+9
-2
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user