From e84eadebdc84d5d383d9dc5dc3fa04b2630f87ce Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Wed, 22 Mar 2017 19:10:33 +0300 Subject: [PATCH] Kapt3: Use 'compilerArgs' safely (KT-16990) 'android-apt' (com.neenbedankt) adds the 'File' instance to 'compilerArgs' (List). --- .../gradle/internal/Kapt3KotlinGradleSubplugin.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/Kapt3KotlinGradleSubplugin.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/Kapt3KotlinGradleSubplugin.kt index a37d162dc13..1bf3e9b427a 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/Kapt3KotlinGradleSubplugin.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/Kapt3KotlinGradleSubplugin.kt @@ -262,7 +262,15 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin { private fun Kapt3SubpluginContext.disableAnnotationProcessingInJavaTask() { (javaCompile as? JavaCompile)?.let { javaCompile -> val options = javaCompile.options - options.compilerArgs = options.compilerArgs.filter { !it.startsWith("-proc:") } + "-proc:none" + // 'android-apt' (com.neenbedankt) adds a File instance to compilerArgs (List). + // Although it's not our problem, we need to handle this case properly. + val oldCompilerArgs: List = options.compilerArgs + val newCompilerArgs = oldCompilerArgs.filterTo(mutableListOf()) { + it !is CharSequence || !it.toString().startsWith("-proc:") + } + newCompilerArgs.add("-proc:none") + @Suppress("UNCHECKED_CAST") + options.compilerArgs = newCompilerArgs as List } }