diff --git a/CHANGELOG.md b/CHANGELOG.md index bbae92d16..1434d5a09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ ### Changed +- The [issue](https://youtrack.jetbrains.com/issue/KT-38576) that required disabling precise Java tracking is not needed anymore. The workaround has been removed. + ### Deprecated ### Removed diff --git a/README.md b/README.md index fa29b4bab..322d8403b 100644 --- a/README.md +++ b/README.md @@ -304,8 +304,7 @@ There is a bug that affects the Anvil Kotlin compiler plugin: The Gradle plugin implements a workaround for this bug, so you shouldn't notice it. Side effects are that incremental Kotlin compilation is disabled for stub generating tasks (which don't run a -full compilation before KAPT anyways). The flag `usePreciseJavaTracking` is disabled, if the -module contains Java code. +full compilation before KAPT anyways). ## Hilt diff --git a/gradle-plugin/src/main/java/com/squareup/anvil/plugin/AnvilPlugin.kt b/gradle-plugin/src/main/java/com/squareup/anvil/plugin/AnvilPlugin.kt index 3d5647729..794dbb441 100644 --- a/gradle-plugin/src/main/java/com/squareup/anvil/plugin/AnvilPlugin.kt +++ b/gradle-plugin/src/main/java/com/squareup/anvil/plugin/AnvilPlugin.kt @@ -116,7 +116,6 @@ internal open class AnvilPlugin : KotlinCompilerPluginSupportPlugin { .extendsFrom(getConfiguration(project, variant.name)) disableIncrementalKotlinCompilation(variant) - disablePreciseJavaTracking(variant) if (!variant.variantFilter.generateDaggerFactoriesOnly) { disableCorrectErrorTypes(variant) @@ -185,35 +184,6 @@ internal open class AnvilPlugin : KotlinCompilerPluginSupportPlugin { version = VERSION ) - private fun disablePreciseJavaTracking(variant: Variant) { - val configureAction: (KotlinCompile) -> Unit = { compileTask -> - val result = CheckMixedSourceSet.preparePreciseJavaTrackingCheck(variant) - - compileTask.doFirstCompat { - // Disable precise java tracking if needed. Note that the doFirst() action only runs - // if the task is not up to date. That's ideal, because if nothing needs to be - // compiled, then we don't need to disable the flag. - // - // We also use the doFirst block to walk through the file system at execution time - // and minimize the IO at configuration time. - CheckMixedSourceSet.disablePreciseJavaTrackingIfNeeded(compileTask, result) - - compileTask.log( - "Anvil: Use precise java tracking: ${compileTask.usePreciseJavaTracking}" - ) - } - } - - variant.compileTaskProvider.configure(configureAction) - - variant.project.pluginManager.withPlugin(KAPT_PLUGIN_ID) { - variant.project - .namedLazy(variant.stubsTaskName) { stubsTaskProvider -> - stubsTaskProvider.configure(configureAction) - } - } - } - private fun disableCorrectErrorTypes(variant: Variant) { variant.project.pluginManager.withPlugin(KAPT_PLUGIN_ID) { // This needs to be disabled, otherwise compiler plugins fail in weird ways when diff --git a/gradle-plugin/src/main/java/com/squareup/anvil/plugin/CheckMixedSourceSet.kt b/gradle-plugin/src/main/java/com/squareup/anvil/plugin/CheckMixedSourceSet.kt deleted file mode 100644 index a2f897669..000000000 --- a/gradle-plugin/src/main/java/com/squareup/anvil/plugin/CheckMixedSourceSet.kt +++ /dev/null @@ -1,73 +0,0 @@ -package com.squareup.anvil.plugin - -import org.gradle.api.Project -import org.gradle.api.file.FileCollection -import org.gradle.api.plugins.JavaPluginExtension -import org.gradle.api.provider.Property -import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -/** - * In a mixed Kotlin / Java source set the Kotlin compiler might crash with an error like this: - * - * java.lang.AssertionError: Duplicated JavaClassDescriptor a/b/c/Hello reported to IC. - * - * That's a known bug: https://youtrack.jetbrains.com/issue/KT-38576 - * - * The workaround for now is to set the kotlin.incremental.usePreciseJavaTracking flag to false for - * these module using this task. - */ -internal object CheckMixedSourceSet { - - fun preparePreciseJavaTrackingCheck(variant: Variant): Input = - Input( - sources = getAndroidSourceDirs(variant) ?: getJvmSourceDirs(variant), - isKaptApplied = variant.project.isKaptApplied() - ) - - fun disablePreciseJavaTrackingIfNeeded( - compileTask: KotlinCompile, - input: Input - ) { - val hasJavaFile = input.sources - ?.asSequence() - ?.flatMap { it.walk() } - ?.filter { it.isFile } - ?.any { it.extension == "java" } - ?: false - - // If there is Java file, then disable precise Java tracking. - // - // If Kapt is enabled then it usually generates Java code making Kotlin compilation use a - // mixed source set. - if (hasJavaFile || input.isKaptApplied.get()) { - compileTask.usePreciseJavaTracking = false - } - } - - private fun getAndroidSourceDirs(variant: Variant): FileCollection? { - return variant.androidVariant - ?.sourceSets - ?.flatMap { it.javaDirectories } - ?.let { variant.project.files(it) } - } - - private fun getJvmSourceDirs(variant: Variant): FileCollection? { - return variant.project.extensions.findByType(JavaPluginExtension::class.java) - ?.sourceSets - ?.single { it.name == variant.name } - ?.allJava - } - - private fun Project.isKaptApplied(): Property = - objects - .property(Boolean::class.java) - .also { - it.set(plugins.hasPlugin(Kapt3GradleSubplugin::class.java)) - } - - class Input( - val sources: FileCollection?, - val isKaptApplied: Property - ) -}