Kapt: Add gradle warnings for Android projects
1. When the old kapt (aka kapt1) is used 2. (for Android projects) When Kotlin plugin is applied but annotationProcessor (Java-only) dependencies are found
This commit is contained in:
+3
@@ -164,6 +164,9 @@ class AnnotationProcessingManager(
|
||||
|
||||
if (aptFiles.isEmpty()) return
|
||||
|
||||
project.logger.warn("${project.name}: " +
|
||||
"Original kapt is deprecated. Please add \"apply plugin: 'kotlin-kapt'\" to your build.gradle.")
|
||||
|
||||
if (project.plugins.findPlugin(ANDROID_APT_PLUGIN_ID) != null) {
|
||||
project.logger.warn("Please do not use `$ANDROID_APT_PLUGIN_ID` with kapt.")
|
||||
}
|
||||
|
||||
+25
-2
@@ -22,6 +22,7 @@ import com.android.builder.model.SourceProvider
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.artifacts.Dependency
|
||||
import org.gradle.api.tasks.SourceSet
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
@@ -60,6 +61,9 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
||||
|
||||
val MAIN_KAPT_CONFIGURATION_NAME = "kapt"
|
||||
|
||||
val KAPT_GROUP_NAME = "org.jetbrains.kotlin"
|
||||
val KAPT_ARTIFACT_NAME = "kotlin-annotation-processing"
|
||||
|
||||
fun getKaptConfigurationName(sourceSetName: String): String {
|
||||
return if (sourceSetName != "main")
|
||||
"$MAIN_KAPT_CONFIGURATION_NAME${sourceSetName.capitalize()}"
|
||||
@@ -336,10 +340,29 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
||||
}
|
||||
|
||||
override fun getCompilerPluginId() = "org.jetbrains.kotlin.kapt3"
|
||||
override fun getGroupName() = "org.jetbrains.kotlin"
|
||||
override fun getArtifactName() = "kotlin-annotation-processing"
|
||||
override fun getGroupName() = KAPT_GROUP_NAME
|
||||
override fun getArtifactName() = KAPT_ARTIFACT_NAME
|
||||
}
|
||||
|
||||
internal fun registerGeneratedJavaSource(kaptTask: KaptTask, javaTask: AbstractCompile) {
|
||||
javaTask.source(kaptTask.destinationDir)
|
||||
}
|
||||
|
||||
internal fun Configuration.getNamedDependencies(): List<Dependency> = allDependencies.filter { it.group != null && it.name != null }
|
||||
|
||||
internal fun checkAndroidAnnotationProcessorDependencyUsage(project: Project) {
|
||||
val isKapt3Enabled = Kapt3GradleSubplugin.isEnabled(project)
|
||||
|
||||
val androidAPDependencies = project.configurations
|
||||
.filter { it.name == "annotationProcessor"
|
||||
|| (it.name.endsWith("AnnotationProcessor") && !it.name.startsWith("_")) }
|
||||
.flatMap { it.getNamedDependencies() }
|
||||
|
||||
if (androidAPDependencies.isNotEmpty()) {
|
||||
val artifactsRendered = androidAPDependencies.joinToString { "'${it.group}:${it.name}:${it.version}'" }
|
||||
val andApplyKapt = if (isKapt3Enabled) "" else " and apply the kapt plugin: \"apply plugin: 'kotlin-kapt'\""
|
||||
project.logger.warn("${project.name}: " +
|
||||
"'androidProcessor' dependencies won't be recognized as kapt annotation processors. " +
|
||||
"Please change the configuration name to 'kapt' for these artifacts: $artifactsRendered$andApplyKapt.")
|
||||
}
|
||||
}
|
||||
+3
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.com.intellij.util.ReflectionUtil
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptionsImpl
|
||||
import org.jetbrains.kotlin.gradle.internal.*
|
||||
import org.jetbrains.kotlin.gradle.internal.Kapt3KotlinGradleSubplugin.Companion.getKaptClasssesDir
|
||||
import org.jetbrains.kotlin.gradle.plugin.android.AndroidGradleWrapper
|
||||
import org.jetbrains.kotlin.gradle.tasks.*
|
||||
import org.jetbrains.kotlin.gradle.utils.ParsedGradleVersion
|
||||
import org.jetbrains.kotlin.incremental.configureMultiProjectIncrementalCompilation
|
||||
@@ -467,6 +468,8 @@ abstract class AbstractAndroidProjectHandler<V>(private val kotlinConfigurationT
|
||||
|
||||
val subpluginEnvironment = loadSubplugins(project)
|
||||
|
||||
checkAndroidAnnotationProcessorDependencyUsage(project)
|
||||
|
||||
forEachVariant(project) {
|
||||
processVariant(it, project, ext, plugin, aptConfigurations, kotlinOptions,
|
||||
kotlinConfigurationTools.kotlinTasksProvider, subpluginEnvironment)
|
||||
|
||||
Reference in New Issue
Block a user