Kapt: Remove generated output directory each time before annotation processing
(cherry picked from commit c4b772a)
This commit is contained in:
committed by
Yan Zhulanow
parent
32d77e5226
commit
00355f3c52
+44
@@ -24,6 +24,7 @@ import java.io.FileFilter
|
||||
class Kapt2IT: BaseGradleIT() {
|
||||
companion object {
|
||||
private const val GRADLE_VERSION = "2.10"
|
||||
private const val GRADLE_2_14_VERSION = "2.14.1"
|
||||
private const val ANDROID_GRADLE_PLUGIN_VERSION = "1.5.+"
|
||||
}
|
||||
|
||||
@@ -165,4 +166,47 @@ class Kapt2IT: BaseGradleIT() {
|
||||
assertFileExists("build/generated/source/kapt2/release/io/realm/DefaultRealmModuleMediator.java")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGeneratedDirectoryIsUpToDate() {
|
||||
val project = Project("generatedDirUpToDate", GRADLE_2_14_VERSION, directoryPrefix = "kapt2")
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
assertKaptSuccessful()
|
||||
assertContains(":compileKotlin")
|
||||
assertContains(":compileJava")
|
||||
assertFileExists("build/classes/main/example/TestClass.class")
|
||||
|
||||
assertFileExists("build/generated/source/kapt2/main/example/TestClassGenerated.java")
|
||||
assertFileExists("build/generated/source/kapt2/main/example/SourceAnnotatedTestClassGenerated.java")
|
||||
assertFileExists("build/generated/source/kapt2/main/example/BinaryAnnotatedTestClassGenerated.java")
|
||||
assertFileExists("build/generated/source/kapt2/main/example/RuntimeAnnotatedTestClassGenerated.java")
|
||||
|
||||
assertFileExists("build/classes/main/example/TestClassGenerated.class")
|
||||
assertFileExists("build/classes/main/example/SourceAnnotatedTestClassGenerated.class")
|
||||
assertFileExists("build/classes/main/example/BinaryAnnotatedTestClassGenerated.class")
|
||||
assertFileExists("build/classes/main/example/RuntimeAnnotatedTestClassGenerated.class")
|
||||
}
|
||||
|
||||
val testKt = project.projectDir.getFileByName("test.kt")
|
||||
testKt.writeText(testKt.readText().replace("@ExampleBinaryAnnotation", ""))
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
assertContains(":compileKotlin")
|
||||
assertContains(":compileJava")
|
||||
assertFileExists("build/classes/main/example/TestClass.class")
|
||||
|
||||
assertFileExists("build/generated/source/kapt2/main/example/TestClassGenerated.java")
|
||||
assertFileExists("build/generated/source/kapt2/main/example/SourceAnnotatedTestClassGenerated.java")
|
||||
/*!*/ assertNoSuchFile("build/generated/source/kapt2/main/example/BinaryAnnotatedTestClassGenerated.java")
|
||||
assertFileExists("build/generated/source/kapt2/main/example/RuntimeAnnotatedTestClassGenerated.java")
|
||||
|
||||
assertFileExists("build/classes/main/example/TestClassGenerated.class")
|
||||
assertFileExists("build/classes/main/example/SourceAnnotatedTestClassGenerated.class")
|
||||
/*!*/ assertNoSuchFile("build/classes/main/example/BinaryAnnotatedTestClassGenerated.class")
|
||||
assertFileExists("build/classes/main/example/RuntimeAnnotatedTestClassGenerated.class")
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url 'file://' + pathToKotlinPlugin
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:0.1-SNAPSHOT"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: "java"
|
||||
apply plugin: "kotlin"
|
||||
apply plugin: "kotlin-kapt"
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url 'file://' + pathToKotlinPlugin
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT"
|
||||
compile "org.jetbrains.kotlin:annotation-processor-example:0.1-SNAPSHOT"
|
||||
kapt "org.jetbrains.kotlin:annotation-processor-example:0.1-SNAPSHOT"
|
||||
}
|
||||
|
||||
task show << {
|
||||
buildscript.configurations.classpath.each { println it }
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
kapt.verbose=true
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example
|
||||
|
||||
@ExampleAnnotation
|
||||
@ExampleSourceAnnotation
|
||||
@ExampleBinaryAnnotation
|
||||
@ExampleRuntimeAnnotation
|
||||
class TestClass
|
||||
+4
@@ -87,6 +87,10 @@ abstract class AbstractAnnotationProcessingExtension(
|
||||
return null
|
||||
}
|
||||
|
||||
// Clean the generated source directory even if we don't run any annotation processors
|
||||
generatedSourcesOutputDir.deleteRecursively()
|
||||
generatedSourcesOutputDir.mkdirs()
|
||||
|
||||
val processors = loadAnnotationProcessors()
|
||||
if (processors.isEmpty()) {
|
||||
log { "No annotation processors detected, exiting" }
|
||||
|
||||
Reference in New Issue
Block a user