From 2a3bab0a0f7305bd7479c308d8b0938f8dbb3027 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Thu, 8 Feb 2018 00:22:07 +0300 Subject: [PATCH] Kapt: Register additional source directories without modifying the raw Gradle model Unfortunately, this works only for the newer Android Studio versions, so we need to keep the old code until IDEA will migrate at least to AS 3.1. --- .../kotlin/kapt/idea/KaptProjectResolverExtension.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/kapt3/kapt3-idea/src/org/jetbrains/kotlin/kapt/idea/KaptProjectResolverExtension.kt b/plugins/kapt3/kapt3-idea/src/org/jetbrains/kotlin/kapt/idea/KaptProjectResolverExtension.kt index 6d13ef61a29..e4f5437d3a7 100644 --- a/plugins/kapt3/kapt3-idea/src/org/jetbrains/kotlin/kapt/idea/KaptProjectResolverExtension.kt +++ b/plugins/kapt3/kapt3-idea/src/org/jetbrains/kotlin/kapt/idea/KaptProjectResolverExtension.kt @@ -110,11 +110,16 @@ class KaptProjectResolverExtension : AbstractProjectResolverExtension() { ideModule.findAndroidModuleModel()?.let { androidModelAny -> // We can cast to AndroidModuleModel cause we already checked in findAndroidModuleModel() that the class exists + val generatedKotlinSources = sourceSet.generatedKotlinSourcesDirFile ?: return + val androidModel = androidModelAny.data as? AndroidModuleModel ?: return val variant = androidModel.findVariantByName(sourceSet.sourceSetName) ?: return + androidModel.registerExtraGeneratedSourceFolder(generatedKotlinSources) + + // TODO remove this when IDEA eventually migrate to the newer Android plugin try { - sourceSet.generatedKotlinSourcesDirFile?.let { variant.mainArtifact.generatedSourceFolders += it } + variant.mainArtifact.generatedSourceFolders += generatedKotlinSources } catch (e: Throwable) { // There was an error being thrown here, but the code above doesn't work for the newer versions of Android Studio 3 // (generatedSourceFolders returns a wrapped unmodifiable list), and the thrown exception breaks the import.