KT-65684: KAPT: (Re)enable fallback to K1 KAPT and make it default

[KAPT] KT-65684 Set languageVersion=1.9 in KaptToolIntegrationTestGenerated

[KAPT] KT-65684 Re-enable a few now-passing tests in Kapt4IT

[KAPT] KT-65684 Fix the logic setting -Xuse-kapt4 flag in Kapt4IT.forceKapt4()

The change is needed to make sure that all the tests have the flag set,
 otherwise some of them would silently switch to the fallback node.
Also disables a few now failing tests.

[KAPT] KT-65684 Revert "KT-64385 Enable K2 KAPT by default"

This reverts commit 7e9d6e60


Merge-request: KT-MR-14291
Merged-by: Pavel Mikhailovskii <Pavel.Mikhailovskii@jetbrains.com>
This commit is contained in:
Pavel Mikhailovskii
2024-02-09 12:54:28 +00:00
committed by Space Team
parent e532220305
commit 7ab9e03347
40 changed files with 459 additions and 127 deletions
@@ -25,6 +25,7 @@ import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.isInfoAsWarnings
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.isKaptKeepKdocCommentsInStubs
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.isKaptVerbose
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.isUseK2
import org.jetbrains.kotlin.gradle.model.builder.KaptModelBuilder
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation
@@ -122,6 +123,10 @@ class Kapt3GradleSubplugin @Inject internal constructor(private val registry: To
return getBooleanOptionValue(BooleanOption.KAPT_KEEP_KDOC_COMMENTS_IN_STUBS)
}
fun Project.isUseK2(): Boolean {
return getBooleanOptionValue(BooleanOption.KAPT_USE_K2)
}
fun Project.classLoadersCacheSize(): Int = findPropertySafe(CLASSLOADERS_CACHE_SIZE)?.toString()?.toInt() ?: 0
fun Project.disableClassloaderCacheForProcessors(): Set<String> {
@@ -213,6 +218,7 @@ class Kapt3GradleSubplugin @Inject internal constructor(private val registry: To
KAPT_INFO_AS_WARNINGS("kapt.info.as.warnings", false),
KAPT_INCLUDE_COMPILE_CLASSPATH("kapt.include.compile.classpath", true),
KAPT_KEEP_KDOC_COMMENTS_IN_STUBS("kapt.keep.kdoc.comments.in.stubs", true),
KAPT_USE_K2("kapt.use.k2", false),
}
}
@@ -532,6 +538,7 @@ internal fun buildKaptSubpluginOptions(
pluginOptions += SubpluginOption("keepKdocCommentsInStubs", "${project.isKaptKeepKdocCommentsInStubs()}")
pluginOptions += SubpluginOption("showProcessorTimings", "${kaptExtension.showProcessorStats}")
pluginOptions += SubpluginOption("detectMemoryLeaks", kaptExtension.detectMemoryLeaks)
pluginOptions += SubpluginOption("useK2", "${project.isUseK2()}")
pluginOptions += SubpluginOption("infoAsWarnings", "${project.isInfoAsWarnings()}")
pluginOptions += FilesSubpluginOption("stubs", kaptStubsDir)
@@ -29,7 +29,6 @@ import org.gradle.workers.WorkerExecutor
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptionsDefault
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptionsHelper
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.create
import org.jetbrains.kotlin.gradle.report.BuildReportMode
@@ -67,6 +66,9 @@ abstract class KaptGenerateStubsTask @Inject constructor(
@get:Input
abstract val verbose: Property<Boolean>
@get:Input
abstract val useK2Kapt: Property<Boolean>
/**
* Changes in this additional sources will trigger stubs regeneration,
* but the sources themselves will not be used to find kapt annotations and generate stubs.
@@ -127,6 +129,10 @@ abstract class KaptGenerateStubsTask @Inject constructor(
args.verbose = verbose.get()
args.destinationAsFile = destinationDirectory.get().asFile
if (useK2Kapt.get()) {
args.freeArgs += "-Xuse-kapt4"
}
}
pluginClasspath { args ->
@@ -148,5 +154,5 @@ abstract class KaptGenerateStubsTask @Inject constructor(
}
override fun isIncrementalCompilationEnabled(): Boolean =
super.isIncrementalCompilationEnabled() && compilerOptions.languageVersion.getOrElse(KotlinVersion.DEFAULT) < KotlinVersion.KOTLIN_2_0
super.isIncrementalCompilationEnabled() && !useK2Kapt.get() && ("-Xuse-kapt4" !in compilerOptions.freeCompilerArgs.get())
}
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension
import org.jetbrains.kotlin.gradle.internal.*
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.KAPT_SUBPLUGIN_ID
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.isIncludeCompileClasspath
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin.Companion.isUseK2
import org.jetbrains.kotlin.gradle.plugin.KaptExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationInfo
@@ -49,6 +50,7 @@ internal class KaptGenerateStubsConfig : BaseKotlinCompileConfig<KaptGenerateStu
configureTask { task ->
task.verbose.set(KaptTask.queryKaptVerboseProperty(project))
task.pluginOptions.add(buildOptions(kaptExtension, task))
task.useK2Kapt.value(project.isUseK2()).finalizeValueOnRead()
if (!isIncludeCompileClasspath(kaptExtension)) {
task.onlyIf {