Add AP option providers of Android Gradle plugin as @Nested to Kapt

Also remove these option providers from the javac task compiler argument
providers so as to avoid output intersections of javac vs kapt.

The options generated by the providers are added to the Kapt subplugin
options as well in order to be passed to Kapt. Since these options
are a list, not a map, pass them without name (Kapt should decode them
into plain arguments). Remove the '-A' prefix as it is there for
command line annotation processor options, but we don't need it, it
is added by Kapt internally.

Issue #KT-23964 Fixed
Issue #KT-24420 Fixed
This commit is contained in:
Sergey Igushkin
2018-05-15 18:40:47 +03:00
parent 77429b1ca5
commit 571905824d
4 changed files with 111 additions and 10 deletions
@@ -16,7 +16,68 @@ class KotlinAndroidGradleIT :
class KotlinAndroidWithJackGradleIT : AbstractKotlinAndroidWithJackGradleTests(androidGradlePluginVersion = "2.3.+")
// TODO If we there is a way to fetch the latest Android plugin version, test against the latest version
class KotlinAndroid32GradleIT : KotlinAndroid3GradleIT(GradleVersionRequired.AtLeast("4.5"), "3.2.0-alpha06")
class KotlinAndroid32GradleIT : KotlinAndroid3GradleIT(GradleVersionRequired.AtLeast("4.6"), "3.2.0-alpha15") {
@Test
fun testKaptUsingApOptionProvidersAsNestedInputOutput() = with(Project("AndroidProject", gradleVersion)) {
setupWorkingDir()
gradleBuildScript(subproject = "Android").appendText(
"""
apply plugin: 'kotlin-kapt'
class MyNested implements org.gradle.process.CommandLineArgumentProvider {
String value = ""
@InputFile
File inputFile = null
@Override
Iterable<String> asArguments() { return [value] }
}
def nested = new MyNested()
nested.value = '123'
nested.inputFile = file("${'$'}projectDir/in.txt")
android.applicationVariants.all {
it.javaCompileOptions.annotationProcessorOptions.compilerArgumentProviders.add(nested)
}
""".trimIndent()
)
File(projectDir, "Android/in.txt").appendText("1234")
val kaptTasks = listOf(":Android:kaptFlavor1DebugKotlin")
val javacTasks = listOf(":Android:compileFlavor1DebugJavaWithJavac")
val buildTasks = (kaptTasks + javacTasks).toTypedArray()
build(*buildTasks) {
assertSuccessful()
assertTasksExecuted(kaptTasks + javacTasks)
}
File(projectDir, "Android/in.txt").appendText("5678")
build(*buildTasks) {
assertSuccessful()
assertTasksExecuted(kaptTasks)
assertTasksUpToDate(javacTasks)
}
gradleBuildScript(subproject = "Android").modify {
it.replace("nested.value = '123'", "nested.value = '456'")
}
build(*buildTasks) {
assertSuccessful()
assertTasksExecuted(kaptTasks)
assertTasksUpToDate(javacTasks)
}
}
}
class KotlinAndroid30GradleIT : KotlinAndroid3GradleIT(GradleVersionRequired.AtLeast("4.1"), "3.0.0")