Kapt: Do now show a warning for APs from 'annotationProcessor' configuration also declared in 'kapt' configuration (#KT-23898)
This commit is contained in:
+35
-9
@@ -406,19 +406,45 @@ internal fun registerGeneratedJavaSource(kaptTask: KaptTask, javaTask: AbstractC
|
|||||||
|
|
||||||
internal fun Configuration.getNamedDependencies(): List<Dependency> = allDependencies.filter { it.group != null && it.name != null }
|
internal fun Configuration.getNamedDependencies(): List<Dependency> = allDependencies.filter { it.group != null && it.name != null }
|
||||||
|
|
||||||
|
private val ANNOTATION_PROCESSOR = "annotationProcessor"
|
||||||
|
private val ANNOTATION_PROCESSOR_CAP = ANNOTATION_PROCESSOR.capitalize()
|
||||||
|
|
||||||
internal fun checkAndroidAnnotationProcessorDependencyUsage(project: Project) {
|
internal fun checkAndroidAnnotationProcessorDependencyUsage(project: Project) {
|
||||||
val isKapt3Enabled = Kapt3GradleSubplugin.isEnabled(project)
|
val isKapt3Enabled = Kapt3GradleSubplugin.isEnabled(project)
|
||||||
|
|
||||||
val androidAPDependencies = project.configurations
|
val apConfigurations = project.configurations
|
||||||
.filter { it.name == "annotationProcessor"
|
.filter { it.name == ANNOTATION_PROCESSOR || (it.name.endsWith(ANNOTATION_PROCESSOR_CAP) && !it.name.startsWith("_")) }
|
||||||
|| (it.name.endsWith("AnnotationProcessor") && !it.name.startsWith("_")) }
|
|
||||||
.flatMap { it.getNamedDependencies() }
|
|
||||||
|
|
||||||
if (androidAPDependencies.isNotEmpty()) {
|
val problemDependencies = mutableListOf<Dependency>()
|
||||||
val artifactsRendered = androidAPDependencies.joinToString { "'${it.group}:${it.name}:${it.version}'" }
|
|
||||||
|
for (apConfiguration in apConfigurations) {
|
||||||
|
val apConfigurationName = apConfiguration.name
|
||||||
|
|
||||||
|
val kaptConfigurationName = when (apConfigurationName) {
|
||||||
|
ANNOTATION_PROCESSOR -> "kapt"
|
||||||
|
else -> {
|
||||||
|
val configurationName = apConfigurationName.dropLast(ANNOTATION_PROCESSOR_CAP.length)
|
||||||
|
Kapt3KotlinGradleSubplugin.getKaptConfigurationName(configurationName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val kaptConfiguration = project.configurations.findByName(kaptConfigurationName) ?: continue
|
||||||
|
val kaptConfigurationDependencies = kaptConfiguration.getNamedDependencies()
|
||||||
|
|
||||||
|
problemDependencies += apConfiguration.getNamedDependencies().filter { a ->
|
||||||
|
// Ignore annotationProcessor dependencies if they are also declared as 'kapt'
|
||||||
|
kaptConfigurationDependencies.none { k -> a.group == k.group && a.name == k.name && a.version == k.version }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (problemDependencies.isNotEmpty()) {
|
||||||
|
val artifactsRendered = problemDependencies.joinToString { "'${it.group}:${it.name}:${it.version}'" }
|
||||||
val andApplyKapt = if (isKapt3Enabled) "" else " and apply the kapt plugin: \"apply plugin: 'kotlin-kapt'\""
|
val andApplyKapt = if (isKapt3Enabled) "" else " and apply the kapt plugin: \"apply plugin: 'kotlin-kapt'\""
|
||||||
project.logger.warn("${project.name}: " +
|
|
||||||
"'annotationProcessor' dependencies won't be recognized as kapt annotation processors. " +
|
project.logger.warn(
|
||||||
"Please change the configuration name to 'kapt' for these artifacts: $artifactsRendered$andApplyKapt.")
|
"${project.name}: " +
|
||||||
|
"'annotationProcessor' dependencies won't be recognized as kapt annotation processors. " +
|
||||||
|
"Please change the configuration name to 'kapt' for these artifacts: $artifactsRendered$andApplyKapt."
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user