K2 kapt: add kapt.use.k2 Gradle property
... and `-Kapt-use-k2` CLI flag to enable K2 kapt. #KT-61114 Fixed
This commit is contained in:
committed by
Space Team
parent
059046a2b1
commit
761221904c
@@ -129,7 +129,8 @@ enum class KaptFlag(val description: String, val defaultValue: Boolean = false)
|
||||
INCREMENTAL_APT("Incremental annotation processing (apt mode)"),
|
||||
STRIP_METADATA("Strip @Metadata annotations from stubs"),
|
||||
KEEP_KDOC_COMMENTS_IN_STUBS("Keep KDoc comments in stubs", defaultValue = true),
|
||||
USE_JVM_IR("Use JVM IR backend", defaultValue = true)
|
||||
USE_JVM_IR("Use JVM IR backend", defaultValue = true),
|
||||
USE_K2("Use K2"),
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ private fun transformKaptToolArgs(args: List<String>, messageCollector: MessageC
|
||||
}
|
||||
KaptCliOption.APT_MODE_OPTION -> aptModePassed = true
|
||||
KaptCliOption.VERBOSE_MODE_OPTION -> kaptVerboseModePassed = true
|
||||
KaptCliOption.USE_K2 -> transformed.add("-Xuse-kapt4")
|
||||
else -> {}
|
||||
}
|
||||
|
||||
|
||||
@@ -221,6 +221,13 @@ enum class KaptCliOption(
|
||||
cliToolOption = CliToolOption("-Kapt-use-jvm-ir", FLAG)
|
||||
),
|
||||
|
||||
USE_K2(
|
||||
"useK2",
|
||||
"true | false",
|
||||
"Use K2",
|
||||
cliToolOption = CliToolOption("-Kapt-use-k2", FLAG)
|
||||
),
|
||||
|
||||
DETECT_MEMORY_LEAKS_OPTION("detectMemoryLeaks", "true | false", "Detect memory leaks in annotation processors"),
|
||||
INCLUDE_COMPILE_CLASSPATH(
|
||||
"includeCompileClasspath",
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
# kapt
|
||||
-language-version 2.0
|
||||
-Xsuppress-version-warnings
|
||||
-Kapt-use-k2=true
|
||||
-Kapt-mode=compile
|
||||
../simple/Test.kt
|
||||
|
||||
# after
|
||||
Return code: 1
|
||||
|
||||
error: [kapt] KAPT "compile" mode is not supported in Kotlin 2.x. Run kapt with -Kapt-mode=stubsAndApt and use kotlinc for the final compilation step.
|
||||
+6
@@ -48,6 +48,12 @@ public class Kapt4ToolIntegrationTestGenerated extends AbstractKapt4ToolIntegrat
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration-kapt4/defaultPackage/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kaptUseK2Flag")
|
||||
public void testKaptUseK2Flag() throws Exception {
|
||||
runTest("plugins/kapt3/kapt3-cli/testData/integration-kapt4/kaptUseK2Flag/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kotlinFileGeneration")
|
||||
public void testKotlinFileGeneration() throws Exception {
|
||||
|
||||
@@ -125,6 +125,7 @@ class Kapt3CommandLineProcessor : CommandLineProcessor {
|
||||
STRIP_METADATA_OPTION -> setFlag(KaptFlag.STRIP_METADATA, value)
|
||||
KEEP_KDOC_COMMENTS_IN_STUBS -> setFlag(KaptFlag.KEEP_KDOC_COMMENTS_IN_STUBS, value)
|
||||
USE_JVM_IR -> setFlag(KaptFlag.USE_JVM_IR, value)
|
||||
USE_K2 -> setFlag(KaptFlag.USE_K2, value)
|
||||
|
||||
SHOW_PROCESSOR_STATS -> setFlag(KaptFlag.SHOW_PROCESSOR_STATS, value)
|
||||
DUMP_PROCESSOR_STATS -> processorsStatsReportFile = File(value)
|
||||
@@ -171,11 +172,13 @@ class Kapt3ComponentRegistrar : ComponentRegistrar {
|
||||
get() = false
|
||||
|
||||
override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
|
||||
if (configuration.getBoolean(USE_FIR)) return
|
||||
val optionsBuilder = (configuration[KAPT_OPTIONS] ?: KaptOptions.Builder())
|
||||
if (configuration.getBoolean(USE_FIR) || KaptFlag.USE_K2 in optionsBuilder.flags) return
|
||||
|
||||
doOpenInternalPackagesIfRequired()
|
||||
val contentRoots = configuration[CLIConfigurationKeys.CONTENT_ROOTS] ?: emptyList()
|
||||
|
||||
val optionsBuilder = (configuration[KAPT_OPTIONS] ?: KaptOptions.Builder()).apply {
|
||||
optionsBuilder.apply {
|
||||
projectBaseDir = project.basePath?.let(::File)
|
||||
compileClasspath.addAll(contentRoots.filterIsInstance<JvmClasspathRoot>().map { it.file })
|
||||
javaSourceRoots.addAll(contentRoots.filterIsInstance<JavaSourceRoot>().map { it.file })
|
||||
|
||||
Reference in New Issue
Block a user