Kapt: Using 'kapt' configuration without the 'kotlin-kapt' plugin applied should throw an error (KT-26145)
This commit is contained in:
+10
@@ -394,6 +394,16 @@ open class Kapt3IT : Kapt3BaseIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNoKaptPluginApplied() {
|
||||
val project = Project("nokapt", directoryPrefix = "kapt2")
|
||||
|
||||
project.build("build") {
|
||||
assertFailed()
|
||||
assertContains("Could not find method kapt() for arguments")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testChangesInLocalAnnotationProcessor() {
|
||||
val project = Project("localAnnotationProcessor", directoryPrefix = "kapt2")
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: "java"
|
||||
apply plugin: "kotlin"
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
compile "org.jetbrains.kotlin:annotation-processor-example:$kotlin_version"
|
||||
kapt "org.jetbrains.kotlin:annotation-processor-example:$kotlin_version"
|
||||
testCompile 'junit:junit:4.12'
|
||||
}
|
||||
|
||||
compileKotlin.kotlinOptions.allWarningsAsErrors = true
|
||||
+1
@@ -0,0 +1 @@
|
||||
fun main(args: Array<String>) {}
|
||||
+2
-2
@@ -100,7 +100,7 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
||||
val KAPT_SUBPLUGIN_ID = "org.jetbrains.kotlin.kapt3"
|
||||
|
||||
fun getKaptConfigurationName(sourceSetName: String): String {
|
||||
return if (sourceSetName != "main")
|
||||
return if (sourceSetName != SourceSet.MAIN_SOURCE_SET_NAME)
|
||||
"$MAIN_KAPT_CONFIGURATION_NAME${sourceSetName.capitalize()}"
|
||||
else
|
||||
MAIN_KAPT_CONFIGURATION_NAME
|
||||
@@ -122,7 +122,7 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
||||
return hasProperty(INFO_AS_WARNINGS) && property(INFO_AS_WARNINGS) == "true"
|
||||
}
|
||||
|
||||
fun findMainKaptConfiguration(project: Project) = project.findKaptConfiguration(MAIN_KAPT_CONFIGURATION_NAME)
|
||||
fun findMainKaptConfiguration(project: Project) = project.findKaptConfiguration(SourceSet.MAIN_SOURCE_SET_NAME)
|
||||
|
||||
fun createAptConfigurationIfNeeded(project: Project, sourceSetName: String): Configuration {
|
||||
val configurationName = Kapt3KotlinGradleSubplugin.getKaptConfigurationName(sourceSetName)
|
||||
|
||||
+21
-2
@@ -161,7 +161,10 @@ internal class Kotlin2JvmSourceSetProcessor(
|
||||
tasksProvider.createKotlinJVMTask(project, taskName, kotlinCompilation)
|
||||
|
||||
override fun doTargetSpecificProcessing() {
|
||||
Kapt3KotlinGradleSubplugin.createAptConfigurationIfNeeded(project, kotlinCompilation.compilationName)
|
||||
ifKaptEnabled(project) {
|
||||
Kapt3KotlinGradleSubplugin.createAptConfigurationIfNeeded(project, kotlinCompilation.compilationName)
|
||||
}
|
||||
|
||||
ScriptingGradleSubplugin.createDiscoveryConfigurationIfNeeded(project, kotlinCompilation.compilationName)
|
||||
|
||||
project.afterEvaluate { project ->
|
||||
@@ -662,7 +665,10 @@ abstract class AbstractAndroidProjectHandler<V>(private val kotlinConfigurationT
|
||||
kotlin.srcDirs(sourceSet.java.srcDirs)
|
||||
}
|
||||
sourceSet.addConvention(KOTLIN_DSL_NAME, kotlinSourceSet)
|
||||
Kapt3KotlinGradleSubplugin.createAptConfigurationIfNeeded(project, sourceSet.name)
|
||||
|
||||
ifKaptEnabled(project) {
|
||||
Kapt3KotlinGradleSubplugin.createAptConfigurationIfNeeded(project, sourceSet.name)
|
||||
}
|
||||
}
|
||||
|
||||
val kotlinOptions = KotlinJvmOptionsImpl()
|
||||
@@ -840,6 +846,19 @@ internal fun createSyncOutputTask(
|
||||
return syncTask
|
||||
}
|
||||
|
||||
private fun ifKaptEnabled(project: Project, block: () -> Unit) {
|
||||
var triggered = false
|
||||
|
||||
fun trigger() {
|
||||
if (triggered) return
|
||||
triggered = true
|
||||
block()
|
||||
}
|
||||
|
||||
project.pluginManager.withPlugin("kotlin-kapt") { trigger() }
|
||||
project.pluginManager.withPlugin("org.jetbrains.kotlin.kapt") { trigger() }
|
||||
}
|
||||
|
||||
private fun SourceSet.clearJavaSrcDirs() {
|
||||
java.setSrcDirs(emptyList<File>())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user