Introduce 'kotlin.experimental.tryK2' gradle property
Once configured this property changed default language version convention for all compiler options to '2.0'. On usage, it produces a warning that it should not be used in production. ^KT-57736 In Progress
This commit is contained in:
committed by
Space Team
parent
c7b100a41a
commit
66648b36df
+158
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.experimental
|
||||
|
||||
import org.gradle.api.logging.LogLevel
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2NativeCompilerArguments
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.jetbrains.kotlin.gradle.util.parseCompilerArgumentsFromBuildOutput
|
||||
import org.jetbrains.kotlin.gradle.utils.EXPERIMENTAL_TRY_K2_WARNING_MESSAGE
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import kotlin.io.path.appendText
|
||||
|
||||
@DisplayName("'kotlin.experimental.tryK2' option")
|
||||
class TryK2IT : KGPBaseTest() {
|
||||
|
||||
@DisplayName("Produces single warning message in multi-project when enabled")
|
||||
@JvmGradlePluginTests
|
||||
@GradleTest
|
||||
fun singleWarningMultiproject(gradleVersion: GradleVersion) {
|
||||
project(
|
||||
"multiprojectWithDependency",
|
||||
gradleVersion,
|
||||
buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.WARN)
|
||||
) {
|
||||
enableTryK2()
|
||||
|
||||
build("--dry-run") {
|
||||
assertOutputContainsExactTimes(EXPERIMENTAL_TRY_K2_WARNING_MESSAGE, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("JVM: language version default is changed to 2.0")
|
||||
@JvmGradlePluginTests
|
||||
@GradleTest
|
||||
fun languageVersionChanged(gradleVersion: GradleVersion) {
|
||||
project(
|
||||
"simpleProject",
|
||||
gradleVersion,
|
||||
buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)
|
||||
) {
|
||||
enableTryK2()
|
||||
|
||||
build("compileKotlin") {
|
||||
assertTasksExecuted(":compileKotlin")
|
||||
|
||||
assertCompilerArgument(":compileKotlin", "-language-version 2.0")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("MPP: language version default is changed to 2.0")
|
||||
@MppGradlePluginTests
|
||||
@GradleTest
|
||||
fun languageVersionChangedMpp(gradleVersion: GradleVersion) {
|
||||
project(
|
||||
"new-mpp-published",
|
||||
gradleVersion,
|
||||
buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)
|
||||
) {
|
||||
enableTryK2()
|
||||
|
||||
build(":compileKotlinMetadata") {
|
||||
assertTasksExecuted(":compileKotlinMetadata")
|
||||
|
||||
assertCompilerArgument(":compileKotlinMetadata", "-language-version 2.0")
|
||||
}
|
||||
|
||||
build(":compileKotlinJvm") {
|
||||
assertTasksExecuted(":compileKotlinJvm")
|
||||
|
||||
assertCompilerArgument(":compileKotlinJvm", "-language-version 2.0")
|
||||
}
|
||||
|
||||
build(":compileKotlinJs") {
|
||||
assertTasksExecuted(":compileKotlinJs")
|
||||
|
||||
assertCompilerArgument(":compileKotlinJs", "-language-version 2.0")
|
||||
}
|
||||
|
||||
build(":compileKotlinLinuxX64") {
|
||||
assertTasksExecuted(":compileKotlinLinuxX64")
|
||||
|
||||
val compileTaskOutput = getOutputForTask(":compileKotlinLinuxX64")
|
||||
val compilerArgs = parseCompilerArgumentsFromBuildOutput(K2NativeCompilerArguments::class, compileTaskOutput)
|
||||
assert(compilerArgs.languageVersion == "2.0") {
|
||||
":compileKotlinLinuxX64 'languageVersion' is not '2.0': ${compilerArgs.languageVersion}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("MPP: language version default is changed to 2.0 for metadata compilations")
|
||||
@MppGradlePluginTests
|
||||
@GradleTest
|
||||
fun languageVersionChangedMppMetadata(gradleVersion: GradleVersion) {
|
||||
project(
|
||||
"commonizeHierarchically",
|
||||
gradleVersion,
|
||||
buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)
|
||||
) {
|
||||
enableTryK2()
|
||||
|
||||
build(":p1:compileAppleAndLinuxMainKotlinMetadata") {
|
||||
assertTasksExecuted(
|
||||
":p1:compileCommonMainKotlinMetadata",
|
||||
":p1:compileConcurrentMainKotlinMetadata",
|
||||
":p1:compileAppleAndLinuxMainKotlinMetadata",
|
||||
)
|
||||
|
||||
assertCompilerArgument(":p1:compileCommonMainKotlinMetadata", "-language-version 2.0")
|
||||
assertCompilerArgument(":p1:compileConcurrentMainKotlinMetadata", "-language-version 2.0")
|
||||
val taskOutput = getOutputForTask(":p1:compileAppleAndLinuxMainKotlinMetadata")
|
||||
val appleAndLinuxMetadataArgs = parseCompilerArgumentsFromBuildOutput(K2NativeCompilerArguments::class, taskOutput)
|
||||
assert(appleAndLinuxMetadataArgs.languageVersion == "2.0") {
|
||||
":compileAppleAndLinuxMainKotlinMetadata 'languageVersion' is not '2.0': ${appleAndLinuxMetadataArgs.languageVersion}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("JVM: explicit user setting for languageVersion is not overridden")
|
||||
@JvmGradlePluginTests
|
||||
@GradleTest
|
||||
fun languageVersionOverride(gradleVersion: GradleVersion) {
|
||||
project(
|
||||
"simpleProject",
|
||||
gradleVersion,
|
||||
buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)
|
||||
) {
|
||||
enableTryK2()
|
||||
|
||||
buildGradle.appendText(
|
||||
"""
|
||||
|
|
||||
|kotlin.compilerOptions.languageVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9)
|
||||
""".trimMargin()
|
||||
)
|
||||
|
||||
build("compileKotlin") {
|
||||
assertTasksExecuted(":compileKotlin")
|
||||
|
||||
assertCompilerArgument(":compileKotlin", "-language-version 1.9")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun TestProject.enableTryK2() = gradleProperties.appendText(
|
||||
"""
|
||||
|
|
||||
|kotlin.experimental.tryK2=true
|
||||
""".trimMargin()
|
||||
)
|
||||
}
|
||||
+16
@@ -236,3 +236,19 @@ fun findParameterInOutput(name: String, output: String): String? =
|
||||
val (key, value) = line.split('=', limit = 2).takeIf { it.size == 2 } ?: return@mapNotNull null
|
||||
if (key.endsWith(name)) value else null
|
||||
}.firstOrNull()
|
||||
|
||||
fun BuildResult.assertCompilerArgument(
|
||||
taskPath: String,
|
||||
expectedArgument: String,
|
||||
) {
|
||||
val taskOutput = getOutputForTask(taskPath)
|
||||
val compilerArguments = taskOutput.lines().first {
|
||||
it.contains("Kotlin compiler args:")
|
||||
}.substringAfter("Kotlin compiler args:")
|
||||
|
||||
assert(compilerArguments.contains(expectedArgument)) {
|
||||
printBuildOutput()
|
||||
|
||||
"$taskPath task compiler arguments don't contain $expectedArgument. Actual content: $compilerArguments"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
kotlin("multiplatform").version("<pluginMarkerVersion>")
|
||||
kotlin("multiplatform")
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
|
||||
+7
-4
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrSingleTargetPreset
|
||||
import org.jetbrains.kotlin.gradle.tasks.CompileUsingKotlinDaemon
|
||||
import org.jetbrains.kotlin.gradle.tasks.withType
|
||||
import org.jetbrains.kotlin.gradle.utils.castIsolatedKotlinPluginClassLoaderAware
|
||||
import org.jetbrains.kotlin.gradle.utils.configureExperimentalTryK2
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
||||
@@ -183,8 +184,9 @@ abstract class KotlinJvmProjectExtension(project: Project) : KotlinSingleJavaTar
|
||||
|
||||
open fun target(body: KotlinWithJavaTarget<KotlinJvmOptions, KotlinJvmCompilerOptions>.() -> Unit) = target.run(body)
|
||||
|
||||
val compilerOptions: KotlinJvmCompilerOptions =
|
||||
project.objects.newInstance(KotlinJvmCompilerOptionsDefault::class.java)
|
||||
val compilerOptions: KotlinJvmCompilerOptions = project.objects
|
||||
.newInstance(KotlinJvmCompilerOptionsDefault::class.java)
|
||||
.configureExperimentalTryK2(project)
|
||||
|
||||
fun compilerOptions(configure: Action<KotlinJvmCompilerOptions>) {
|
||||
configure.execute(compilerOptions)
|
||||
@@ -406,8 +408,9 @@ abstract class KotlinAndroidProjectExtension(project: Project) : KotlinSingleTar
|
||||
|
||||
open fun target(body: KotlinAndroidTarget.() -> Unit) = target.run(body)
|
||||
|
||||
val compilerOptions: KotlinJvmCompilerOptions =
|
||||
project.objects.newInstance(KotlinJvmCompilerOptionsDefault::class.java)
|
||||
val compilerOptions: KotlinJvmCompilerOptions = project.objects
|
||||
.newInstance(KotlinJvmCompilerOptionsDefault::class.java)
|
||||
.configureExperimentalTryK2(project)
|
||||
|
||||
fun compilerOptions(configure: Action<KotlinJvmCompilerOptions>) {
|
||||
configure.execute(compilerOptions)
|
||||
|
||||
+1
-1
@@ -434,7 +434,7 @@ class Kapt3GradleSubplugin @Inject internal constructor(private val registry: To
|
||||
|
||||
private fun Kapt3SubpluginContext.createKaptGenerateStubsTask(): TaskProvider<KaptGenerateStubsTask> {
|
||||
val kaptTaskName = kotlinCompile.kaptGenerateStubsTaskName
|
||||
val kaptTaskProvider = project.registerTask<KaptGenerateStubsTask>(kaptTaskName)
|
||||
val kaptTaskProvider = project.registerTask<KaptGenerateStubsTask>(kaptTaskName, listOf(project))
|
||||
|
||||
val taskConfig = KaptGenerateStubsConfig(kotlinCompilation)
|
||||
taskConfig.configureTask {
|
||||
|
||||
+7
-2
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.internal
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.*
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.api.file.ConfigurableFileCollection
|
||||
@@ -33,6 +34,7 @@ import org.jetbrains.kotlin.gradle.report.BuildReportMode
|
||||
import org.jetbrains.kotlin.gradle.tasks.KaptGenerateStubs
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.toSingleCompilerPluginOptions
|
||||
import org.jetbrains.kotlin.gradle.utils.configureExperimentalTryK2
|
||||
import org.jetbrains.kotlin.gradle.utils.toPathsArray
|
||||
import org.jetbrains.kotlin.incremental.classpathAsList
|
||||
import org.jetbrains.kotlin.incremental.destinationAsFile
|
||||
@@ -40,10 +42,13 @@ import javax.inject.Inject
|
||||
|
||||
@CacheableTask
|
||||
abstract class KaptGenerateStubsTask @Inject constructor(
|
||||
project: Project,
|
||||
workerExecutor: WorkerExecutor,
|
||||
objectFactory: ObjectFactory
|
||||
objectFactory: ObjectFactory,
|
||||
) : KotlinCompile(
|
||||
objectFactory.newInstance(KotlinJvmCompilerOptionsDefault::class.java),
|
||||
objectFactory
|
||||
.newInstance(KotlinJvmCompilerOptionsDefault::class.java)
|
||||
.configureExperimentalTryK2(project),
|
||||
workerExecutor,
|
||||
objectFactory
|
||||
), KaptGenerateStubs {
|
||||
|
||||
+4
-2
@@ -10,6 +10,7 @@ import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
||||
import org.jetbrains.kotlin.gradle.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaTarget
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||
import org.jetbrains.kotlin.gradle.utils.configureExperimentalTryK2
|
||||
|
||||
@Deprecated(
|
||||
message = "Should be removed with Js platform plugin",
|
||||
@@ -38,8 +39,9 @@ internal open class Kotlin2JsPlugin(
|
||||
targetName,
|
||||
{
|
||||
object : HasCompilerOptions<KotlinJsCompilerOptions> {
|
||||
override val options: KotlinJsCompilerOptions =
|
||||
project.objects.newInstance(KotlinJsCompilerOptionsDefault::class.java)
|
||||
override val options: KotlinJsCompilerOptions = project.objects
|
||||
.newInstance(KotlinJsCompilerOptionsDefault::class.java)
|
||||
.configureExperimentalTryK2(project)
|
||||
}
|
||||
},
|
||||
{ compilerOptions: KotlinJsCompilerOptions ->
|
||||
|
||||
+5
-2
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.configuration.KaptGenerateStubsConfig
|
||||
import org.jetbrains.kotlin.gradle.tasks.configuration.KaptWithoutKotlincConfig
|
||||
import org.jetbrains.kotlin.gradle.tasks.configuration.KotlinCompileConfig
|
||||
import org.jetbrains.kotlin.gradle.utils.configureExperimentalTryK2
|
||||
|
||||
/** Plugin that can be used by third-party plugins to create Kotlin-specific DSL and tasks (compilation and KAPT) for JVM platform. */
|
||||
abstract class KotlinBaseApiPlugin : DefaultKotlinBasePlugin(), KotlinJvmFactory {
|
||||
@@ -42,7 +43,9 @@ abstract class KotlinBaseApiPlugin : DefaultKotlinBasePlugin(), KotlinJvmFactory
|
||||
}
|
||||
|
||||
override fun createCompilerJvmOptions(): KotlinJvmCompilerOptions {
|
||||
return myProject.objects.newInstance(KotlinJvmCompilerOptionsDefault::class.java)
|
||||
return myProject.objects
|
||||
.newInstance(KotlinJvmCompilerOptionsDefault::class.java)
|
||||
.configureExperimentalTryK2(myProject)
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@@ -72,7 +75,7 @@ abstract class KotlinBaseApiPlugin : DefaultKotlinBasePlugin(), KotlinJvmFactory
|
||||
|
||||
override fun registerKaptGenerateStubsTask(taskName: String): TaskProvider<out KaptGenerateStubs> {
|
||||
val taskConfig = KaptGenerateStubsConfig(myProject, kotlinExtension, kaptExtension)
|
||||
return myProject.registerTask(taskName, KaptGenerateStubsTask::class.java, emptyList()).also {
|
||||
return myProject.registerTask(taskName, KaptGenerateStubsTask::class.java, listOf(myProject)).also {
|
||||
taskConfig.execute(it)
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -10,6 +10,7 @@ import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
||||
import org.jetbrains.kotlin.gradle.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaTarget
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||
import org.jetbrains.kotlin.gradle.utils.configureExperimentalTryK2
|
||||
|
||||
internal open class KotlinCommonPlugin(
|
||||
registry: ToolingModelBuilderRegistry
|
||||
@@ -34,8 +35,9 @@ internal open class KotlinCommonPlugin(
|
||||
targetName,
|
||||
{
|
||||
object : HasCompilerOptions<KotlinMultiplatformCommonCompilerOptions> {
|
||||
override val options: KotlinMultiplatformCommonCompilerOptions =
|
||||
project.objects.newInstance(KotlinMultiplatformCommonCompilerOptionsDefault::class.java)
|
||||
override val options: KotlinMultiplatformCommonCompilerOptions = project.objects
|
||||
.newInstance(KotlinMultiplatformCommonCompilerOptionsDefault::class.java)
|
||||
.configureExperimentalTryK2(project)
|
||||
}
|
||||
},
|
||||
{ compilerOptions: KotlinMultiplatformCommonCompilerOptions ->
|
||||
|
||||
+4
-1
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPro
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.scripting.internal.ScriptingGradleSubplugin
|
||||
import org.jetbrains.kotlin.gradle.tasks.*
|
||||
import org.jetbrains.kotlin.gradle.utils.configureExperimentalTryK2
|
||||
|
||||
const val KOTLIN_DSL_NAME = "kotlin"
|
||||
|
||||
@@ -59,7 +60,9 @@ internal open class KotlinJvmPlugin(
|
||||
{
|
||||
object : HasCompilerOptions<KotlinJvmCompilerOptions> {
|
||||
override val options: KotlinJvmCompilerOptions =
|
||||
project.objects.newInstance(KotlinJvmCompilerOptionsDefault::class.java)
|
||||
project.objects
|
||||
.newInstance(KotlinJvmCompilerOptionsDefault::class.java)
|
||||
.configureExperimentalTryK2(project)
|
||||
}
|
||||
},
|
||||
{ compilerOptions: KotlinJvmCompilerOptions ->
|
||||
|
||||
+2
@@ -99,6 +99,8 @@ abstract class DefaultKotlinBasePlugin : KotlinBasePlugin {
|
||||
}
|
||||
|
||||
BuildMetricsService.registerIfAbsent(project)
|
||||
|
||||
project.warnExperimentalTryK2IsEnabled()
|
||||
}
|
||||
|
||||
private fun addKotlinCompilerConfiguration(project: Project) {
|
||||
|
||||
+9
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
|
||||
import org.jetbrains.kotlin.cli.common.toBooleanLenient
|
||||
@@ -19,6 +20,7 @@ import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLI
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_COMPILER_KEEP_INCREMENTAL_COMPILATION_CACHES_IN_MEMORY
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_COMPILER_USE_PRECISE_COMPILATION_RESULTS_BACKUP
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_CREATE_DEFAULT_MULTIPLATFORM_PUBLICATIONS
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_EXPERIMENTAL_TRY_K2
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_JS_KARMA_BROWSERS
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ALLOW_LEGACY_DEPENDENCIES
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ANDROID_GRADLE_PLUGIN_COMPATIBILITY_NO_WARN
|
||||
@@ -518,6 +520,12 @@ internal class PropertiesProvider private constructor(private val project: Proje
|
||||
val allowLegacyMppDependencies: Boolean
|
||||
get() = booleanProperty(KOTLIN_MPP_ALLOW_LEGACY_DEPENDENCIES) ?: false
|
||||
|
||||
val kotlinExperimentalTryK2: Provider<Boolean> = project.providers
|
||||
.provider<Boolean> {
|
||||
booleanProperty(KOTLIN_EXPERIMENTAL_TRY_K2)
|
||||
}
|
||||
.orElse(false)
|
||||
|
||||
/**
|
||||
* Retrieves a comma-separated list of browsers to use when running karma tests for [target]
|
||||
* @see KOTLIN_JS_KARMA_BROWSERS
|
||||
@@ -606,6 +614,7 @@ internal class PropertiesProvider private constructor(private val project: Proje
|
||||
const val KOTLIN_CREATE_DEFAULT_MULTIPLATFORM_PUBLICATIONS = "kotlin.internal.mpp.createDefaultMultiplatformPublications"
|
||||
const val KOTLIN_RUN_COMPILER_VIA_BUILD_TOOLS_API = "kotlin.compiler.runViaBuildToolsApi"
|
||||
const val KOTLIN_MPP_ALLOW_LEGACY_DEPENDENCIES = "kotlin.mpp.allow.legacy.dependencies"
|
||||
const val KOTLIN_EXPERIMENTAL_TRY_K2 = "kotlin.experimental.tryK2"
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+10
-6
@@ -9,12 +9,14 @@ import org.jetbrains.kotlin.gradle.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.HasCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.native.NativeCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.utils.configureExperimentalTryK2
|
||||
|
||||
internal object KotlinMultiplatformCommonCompilerOptionsFactory : KotlinCompilationImplFactory.KotlinCompilerOptionsFactory {
|
||||
override fun create(target: KotlinTarget, compilationName: String): KotlinCompilationImplFactory.KotlinCompilerOptionsFactory.Options {
|
||||
val compilerOptions = object : HasCompilerOptions<KotlinMultiplatformCommonCompilerOptions> {
|
||||
override val options: KotlinMultiplatformCommonCompilerOptions =
|
||||
target.project.objects.newInstance(KotlinMultiplatformCommonCompilerOptionsDefault::class.java)
|
||||
override val options: KotlinMultiplatformCommonCompilerOptions = target.project.objects
|
||||
.newInstance(KotlinMultiplatformCommonCompilerOptionsDefault::class.java)
|
||||
.configureExperimentalTryK2(target.project)
|
||||
}
|
||||
|
||||
val kotlinOptions = object : KotlinCommonOptions {
|
||||
@@ -43,8 +45,9 @@ internal object KotlinNativeCompilerOptionsFactory : KotlinCompilationImplFactor
|
||||
internal object KotlinJsCompilerOptionsFactory : KotlinCompilationImplFactory.KotlinCompilerOptionsFactory {
|
||||
override fun create(target: KotlinTarget, compilationName: String): KotlinCompilationImplFactory.KotlinCompilerOptionsFactory.Options {
|
||||
val compilerOptions = object : HasCompilerOptions<KotlinJsCompilerOptions> {
|
||||
override val options: KotlinJsCompilerOptions =
|
||||
target.project.objects.newInstance(KotlinJsCompilerOptionsDefault::class.java)
|
||||
override val options: KotlinJsCompilerOptions = target.project.objects
|
||||
.newInstance(KotlinJsCompilerOptionsDefault::class.java)
|
||||
.configureExperimentalTryK2(target.project)
|
||||
}
|
||||
|
||||
val kotlinOptions = object : KotlinJsOptions {
|
||||
@@ -59,8 +62,9 @@ internal object KotlinJsCompilerOptionsFactory : KotlinCompilationImplFactory.Ko
|
||||
internal object KotlinJvmCompilerOptionsFactory : KotlinCompilationImplFactory.KotlinCompilerOptionsFactory {
|
||||
override fun create(target: KotlinTarget, compilationName: String): KotlinCompilationImplFactory.KotlinCompilerOptionsFactory.Options {
|
||||
val compilerOptions = object : HasCompilerOptions<KotlinJvmCompilerOptions> {
|
||||
override val options: KotlinJvmCompilerOptions =
|
||||
target.project.objects.newInstance(KotlinJvmCompilerOptionsDefault::class.java)
|
||||
override val options: KotlinJvmCompilerOptions = target.project.objects
|
||||
.newInstance(KotlinJvmCompilerOptionsDefault::class.java)
|
||||
.configureExperimentalTryK2(target.project)
|
||||
}
|
||||
|
||||
val kotlinOptions = object : KotlinJvmOptions {
|
||||
|
||||
+4
-2
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.gradle.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.archivesName
|
||||
import org.jetbrains.kotlin.gradle.utils.configureExperimentalTryK2
|
||||
import javax.inject.Inject
|
||||
|
||||
abstract class GradleKpmJvmVariant @Inject constructor(
|
||||
@@ -40,8 +41,9 @@ class GradleKpmJvmVariantCompilationData(val variant: GradleKpmJvmVariant) : Gra
|
||||
|
||||
override val compilerOptions: HasCompilerOptions<KotlinJvmCompilerOptions> =
|
||||
object : HasCompilerOptions<KotlinJvmCompilerOptions> {
|
||||
override val options: KotlinJvmCompilerOptions =
|
||||
variant.project.objects.newInstance(KotlinJvmCompilerOptionsDefault::class.java)
|
||||
override val options: KotlinJvmCompilerOptions = variant.project.objects
|
||||
.newInstance(KotlinJvmCompilerOptionsDefault::class.java)
|
||||
.configureExperimentalTryK2(variant.project)
|
||||
}
|
||||
|
||||
// TODO pull out to the variant
|
||||
|
||||
+3
-2
@@ -116,8 +116,9 @@ internal open class GradleKpmCommonFragmentMetadataCompilationDataImpl(
|
||||
|
||||
override val compilerOptions: HasCompilerOptions<KotlinMultiplatformCommonCompilerOptions> =
|
||||
object : HasCompilerOptions<KotlinMultiplatformCommonCompilerOptions> {
|
||||
override val options: KotlinMultiplatformCommonCompilerOptions =
|
||||
project.objects.newInstance(KotlinMultiplatformCommonCompilerOptionsDefault::class.java)
|
||||
override val options: KotlinMultiplatformCommonCompilerOptions = project.objects
|
||||
.newInstance(KotlinMultiplatformCommonCompilerOptionsDefault::class.java)
|
||||
.configureExperimentalTryK2(project)
|
||||
}
|
||||
|
||||
|
||||
|
||||
+5
-2
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
@@ -23,6 +24,7 @@ import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode.DEVELOPMENT
|
||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
import org.jetbrains.kotlin.gradle.utils.configureExperimentalTryK2
|
||||
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
||||
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
|
||||
@@ -30,10 +32,11 @@ import javax.inject.Inject
|
||||
|
||||
@CacheableTask
|
||||
abstract class KotlinJsIrLink @Inject constructor(
|
||||
project: Project,
|
||||
objectFactory: ObjectFactory,
|
||||
workerExecutor: WorkerExecutor
|
||||
workerExecutor: WorkerExecutor,
|
||||
) : Kotlin2JsCompile(
|
||||
objectFactory.newInstance(KotlinJsCompilerOptionsDefault::class.java),
|
||||
objectFactory.newInstance(KotlinJsCompilerOptionsDefault::class.java).configureExperimentalTryK2(project),
|
||||
objectFactory,
|
||||
workerExecutor
|
||||
) {
|
||||
|
||||
+4
-2
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||
import org.jetbrains.kotlin.gradle.utils.SingleWarningPerBuild
|
||||
import org.jetbrains.kotlin.gradle.utils.configureExperimentalTryK2
|
||||
|
||||
class KotlinJvmWithJavaTargetPreset(
|
||||
private val project: Project
|
||||
@@ -36,8 +37,9 @@ class KotlinJvmWithJavaTargetPreset(
|
||||
name,
|
||||
{
|
||||
object : HasCompilerOptions<KotlinJvmCompilerOptions> {
|
||||
override val options: KotlinJvmCompilerOptions =
|
||||
project.objects.newInstance(KotlinJvmCompilerOptionsDefault::class.java)
|
||||
override val options: KotlinJvmCompilerOptions = project.objects
|
||||
.newInstance(KotlinJvmCompilerOptionsDefault::class.java)
|
||||
.configureExperimentalTryK2(project)
|
||||
}
|
||||
},
|
||||
{ compilerOptions: KotlinJvmCompilerOptions ->
|
||||
|
||||
+2
@@ -11,12 +11,14 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinNativeCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinNativeCompilerOptionsDefault
|
||||
import org.jetbrains.kotlin.gradle.plugin.HasCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.applyLanguageSettingsToCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.utils.configureExperimentalTryK2
|
||||
import org.jetbrains.kotlin.project.model.LanguageSettings
|
||||
|
||||
class NativeCompilerOptions(project: Project) : HasCompilerOptions<KotlinCommonCompilerOptions> {
|
||||
|
||||
override val options: KotlinNativeCompilerOptions = project.objects
|
||||
.newInstance(KotlinNativeCompilerOptionsDefault::class.java)
|
||||
.configureExperimentalTryK2(project)
|
||||
|
||||
internal fun syncLanguageSettings(languageSettings: LanguageSettings) {
|
||||
applyLanguageSettingsToCompilerOptions(languageSettings, options)
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ internal open class KotlinTasksProvider {
|
||||
fun registerKotlinJsIrTask(
|
||||
project: Project, taskName: String, configuration: KotlinJsIrLinkConfig
|
||||
): TaskProvider<out KotlinJsIrLink> {
|
||||
return project.registerTask(taskName, KotlinJsIrLink::class.java).also {
|
||||
return project.registerTask(taskName, KotlinJsIrLink::class.java, listOf(project)).also {
|
||||
configuration.execute(it)
|
||||
}
|
||||
}
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.utils
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
|
||||
|
||||
internal fun <T : KotlinCommonCompilerOptions> T.configureExperimentalTryK2(
|
||||
project: Project,
|
||||
kotlinProperties: PropertiesProvider = project.kotlinPropertiesProvider
|
||||
): T = configureExperimentalTryK2(kotlinProperties)
|
||||
|
||||
internal fun <T : KotlinCommonCompilerOptions> T.configureExperimentalTryK2(
|
||||
kotlinProperties: PropertiesProvider
|
||||
): T = apply {
|
||||
languageVersion.convention(
|
||||
kotlinProperties.kotlinExperimentalTryK2.map { enabled ->
|
||||
@Suppress("TYPE_MISMATCH")
|
||||
if (enabled) KotlinVersion.KOTLIN_2_0 else null
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
internal fun Project.warnExperimentalTryK2IsEnabled() {
|
||||
if (project.kotlinPropertiesProvider.kotlinExperimentalTryK2.get()) {
|
||||
SingleWarningPerBuild.show(this, EXPERIMENTAL_TRY_K2_WARNING_MESSAGE)
|
||||
}
|
||||
}
|
||||
|
||||
val EXPERIMENTAL_TRY_K2_WARNING_MESSAGE =
|
||||
"""
|
||||
ATTENTION: 'kotlin.experimental.tryK2' is an experimental option enabled in the project for trying out the new Kotlin K2 compiler only.
|
||||
Please refrain from using it in production code and provide feedback to the Kotlin team for any issues encountered via https://kotl.in/issue
|
||||
""".trimIndent()
|
||||
Reference in New Issue
Block a user