From a35f2eb90ec071c4d0dda41a00a7d00ddc4ba192 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Tue, 10 Oct 2023 14:30:18 +0300 Subject: [PATCH] Build: switch language level for compilation to 2.0 KT-61951 --- gradle.properties | 2 +- .../tools/kotlin-stdlib-gen/build.gradle | 2 +- .../src/main/kotlin/LibrariesCommon.kt | 1 + .../kotlin/common-configuration.gradle.kts | 123 ++++-------------- 4 files changed, 29 insertions(+), 99 deletions(-) diff --git a/gradle.properties b/gradle.properties index ffa57cb503b..3c05841a8b4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,7 +27,7 @@ systemProp.org.gradle.internal.http.socketTimeout=90000 cacheRedirectorEnabled=true defaultSnapshotVersion=2.0.255-SNAPSHOT -kotlinLanguageVersion=1.9 +kotlinLanguageVersion=2.0 kotlin.build.gradlePlugin.version=0.0.39 diff --git a/libraries/tools/kotlin-stdlib-gen/build.gradle b/libraries/tools/kotlin-stdlib-gen/build.gradle index 42e1dad9047..c4cf63ee8ad 100644 --- a/libraries/tools/kotlin-stdlib-gen/build.gradle +++ b/libraries/tools/kotlin-stdlib-gen/build.gradle @@ -14,7 +14,7 @@ dependencies { compileKotlin { kotlinOptions { - freeCompilerArgs = ["-version"] + freeCompilerArgs = ["-version", "-Xdont-warn-on-error-suppression"] } } diff --git a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/LibrariesCommon.kt b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/LibrariesCommon.kt index 5815cf0d52f..4decdb33da3 100644 --- a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/LibrariesCommon.kt +++ b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/LibrariesCommon.kt @@ -82,6 +82,7 @@ fun Project.configureFrontendIr() = tasks.withType().configure } if (languageVersion.get() >= KotlinVersion.KOTLIN_2_0) { languageVersion.set(KotlinVersion.KOTLIN_1_9) + apiVersion.set(KotlinVersion.KOTLIN_1_9) progressiveMode.set(false) } } diff --git a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/common-configuration.gradle.kts b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/common-configuration.gradle.kts index a161e653bd7..8d922d106c9 100644 --- a/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/common-configuration.gradle.kts +++ b/repo/gradle-build-conventions/buildsrc-compat/src/main/kotlin/common-configuration.gradle.kts @@ -118,7 +118,8 @@ fun Project.configureKotlinCompilationOptions() { plugins.withType { val commonCompilerArgs = listOfNotNull( "-opt-in=kotlin.RequiresOptIn", - "-progressive".takeIf { getBooleanProperty("test.progressive.mode") ?: false } + "-progressive".takeIf { getBooleanProperty("test.progressive.mode") ?: false }, + "-Xdont-warn-on-error-suppression", ) val kotlinLanguageVersion: String by rootProject.extra @@ -127,12 +128,33 @@ fun Project.configureKotlinCompilationOptions() { val useFirIC by extra(project.kotlinBuildProperties.useFirTightIC) val renderDiagnosticNames by extra(project.kotlinBuildProperties.renderDiagnosticNames) - @Suppress("DEPRECATION") + val coreLibProjects: List by rootProject.extra + val projectsWithForced19LanguageVersion = coreLibProjects + listOf( + ":kotlin-stdlib-jvm-minimal-for-test", + ":kotlin-stdlib-js-ir-minimal-for-test", + ":kotlin-stdlib-wasm-js", + ":kotlin-stdlib-wasm-wasi", + ":kotlin-dom-api-compat", + ":kotlin-test:kotlin-test-wasm-js", + ":kotlin-test:kotlin-test-wasm-wasi", + ) + tasks.withType>().configureEach { kotlinOptions { - languageVersion = kotlinLanguageVersion - apiVersion = kotlinLanguageVersion + freeCompilerArgs += commonCompilerArgs + val forced19 = project.path in projectsWithForced19LanguageVersion + if (forced19) { + languageVersion = "1.9" + apiVersion = "1.9" + } else { + languageVersion = kotlinLanguageVersion + apiVersion = kotlinLanguageVersion + freeCompilerArgs += "-Xskip-prerelease-check" + } + if (KotlinVersion.DEFAULT >= KotlinVersion.KOTLIN_2_0 && forced19) { + options.progressiveMode.set(false) + } } val relativePathBaseArg: String? = @@ -143,7 +165,6 @@ fun Project.configureKotlinCompilationOptions() { // Workaround to avoid remote build cache misses due to absolute paths in relativePathBaseArg doFirst { if (relativePathBaseArg != null) { - @Suppress("DEPRECATION") kotlinOptions.freeCompilerArgs += relativePathBaseArg } } @@ -154,79 +175,6 @@ fun Project.configureKotlinCompilationOptions() { "-Xno-kotlin-nothing-value-exception", ) - val coreLibProjects: List by rootProject.extra - // Check prepare/kotlin-gradle-plugin-compiler-dependencies/build.gradle.kts to find out why there're some specific compiler modules - val kgpAndDependencies = listOf( - ":atomicfu", - ":compiler:build-tools:kotlin-build-statistics", - ":compiler:build-tools:kotlin-build-tools-api", - ":compiler:cli", - ":compiler:cli-base", - ":compiler:cli-common", - ":compiler:compiler.version", - ":compiler:config", - ":compiler:config.jvm", - ":compiler:frontend", - ":compiler:ir.serialization.common", - ":compiler:ir.tree", - ":compiler:util", - ":core:compiler.common", - ":core:compiler.common.jvm", - ":core:compiler.common.native", - ":core:descriptors", - ":core:deserialization", - ":core:deserialization.common", - ":core:metadata", - ":core:util.runtime", - ":daemon-common", - ":gradle:android-test-fixes", - ":gradle:gradle-warnings-detector", - ":gradle:kotlin-compiler-args-properties", - ":js:js.config", - ":kotlin-allopen", - ":kotlin-assignment", - ":kotlin-build-common", - ":kotlin-build-tools-enum-compat", - ":kotlin-compiler-runner-unshaded", - ":kotlin-daemon-client", - ":kotlin-gradle-build-metrics", - ":kotlin-gradle-compiler-types", - ":kotlin-gradle-plugin", - ":kotlin-gradle-plugin-annotations", - ":kotlin-gradle-plugin-api", - ":kotlin-gradle-plugin-idea", - ":kotlin-gradle-plugin-idea-proto", - ":kotlin-gradle-plugin-model", - ":kotlin-gradle-statistics", - ":kotlin-gradle-subplugin-example", - ":kotlin-lombok", - ":kotlin-noarg", - ":kotlin-project-model", - ":kotlin-sam-with-receiver", - ":kotlin-serialization", - ":kotlin-tooling-core", - ":kotlin-tooling-metadata", - ":kotlin-util-io", - ":kotlin-util-klib", - ":native:kotlin-klib-commonizer-api", - ":native:kotlin-native-utils", - ) - val projectsWithDisabledFirBootstrap = coreLibProjects + kgpAndDependencies + listOf( - ":kotlinx-metadata", - ":kotlinx-metadata-jvm", - // For some reason stdlib isn't imported correctly for this module - // Probably it's related to kotlin-test module usage - ":kotlin-gradle-statistics", - // Requires serialization plugin - ":wasm:wasm.ir", - // Uses multiplatform - ":kotlin-stdlib-jvm-minimal-for-test", - ":kotlin-native:endorsedLibraries:kotlinx.cli", - ":kotlin-native:klib", - // Requires serialization plugin - ":js:js.tests", - ) - // TODO: fix remaining warnings and remove this property. val tasksWithWarnings = listOf( ":kotlin-gradle-plugin:compileCommonKotlin", @@ -240,25 +188,6 @@ fun Project.configureKotlinCompilationOptions() { tasks.withType().configureEach { kotlinOptions { freeCompilerArgs += jvmCompilerArgs - - if (useJvmFir) { - if (project.path !in projectsWithDisabledFirBootstrap) { - freeCompilerArgs += "-Xuse-k2" - freeCompilerArgs += "-Xabi-stability=stable" - if (useFirLT) { - freeCompilerArgs += "-Xuse-fir-lt" - } - if (useFirIC) { - freeCompilerArgs += "-Xuse-fir-ic" - } - } else { - freeCompilerArgs += "-Xskip-prerelease-check" - } - } - if (KotlinVersion.DEFAULT >= KotlinVersion.KOTLIN_2_0 && project.path in projectsWithDisabledFirBootstrap) { - languageVersion = "1.9" - options.progressiveMode.set(false) - } if (renderDiagnosticNames) { freeCompilerArgs += "-Xrender-internal-diagnostic-names" }