diff --git a/buildSrc/src/main/kotlin/GradleCommon.kt b/buildSrc/src/main/kotlin/GradleCommon.kt index 7659bf1b189..7806b458703 100644 --- a/buildSrc/src/main/kotlin/GradleCommon.kt +++ b/buildSrc/src/main/kotlin/GradleCommon.kt @@ -29,6 +29,7 @@ import org.jetbrains.dokka.DokkaVersion import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.dokka.gradle.GradleExternalDocumentationLinkBuilder import org.jetbrains.kotlin.gradle.dsl.KotlinSingleJavaTargetExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import plugins.configureDefaultPublishing @@ -504,15 +505,25 @@ private fun Project.commonVariantAttributes(): Action = Action().configureEach { - kotlinOptions.languageVersion = "1.4" - kotlinOptions.apiVersion = "1.4" - kotlinOptions.freeCompilerArgs += listOf( - "-Xskip-prerelease-check", - "-Xsuppress-version-warnings", - "-Xuse-ir" // Needed as long as languageVersion is less than 1.5. - ) + compilerOptions { + // check https://docs.gradle.org/current/userguide/compatibility.html#kotlin for Kotlin-Gradle versions matrix + @Suppress("DEPRECATION") // we can't use language version greater than 1.5 as minimal supported Gradle embeds Kotlin 1.4 + languageVersion.set(KotlinVersion.KOTLIN_1_5) + @Suppress("DEPRECATION") // we can't use api version greater than 1.4 as minimal supported Gradle version uses kotlin-stdlib 1.4 + apiVersion.set(KotlinVersion.KOTLIN_1_4) + freeCompilerArgs.addAll( + listOf( + "-Xskip-prerelease-check", + "-Xsuppress-version-warnings", + // We have to override the default value for `-Xsam-conversions` to `class` + // otherwise the compiler would compile lambdas using invokedynamic, + // such lambdas are not serializable so are not compatible with Gradle configuration cache. + // It doesn't lead to a significant difference in binaries sizes, and previously (before LV 1.5) the `class` value was set by default. + "-Xsam-conversions=class", + ) + ) + } } } diff --git a/compiler/util-io/build.gradle.kts b/compiler/util-io/build.gradle.kts index 29fe5bd2294..4e600cdcae6 100644 --- a/compiler/util-io/build.gradle.kts +++ b/compiler/util-io/build.gradle.kts @@ -14,15 +14,7 @@ sourceSets { "test" { projectDefault() } } -tasks { - withType { - kotlinOptions { - languageVersion = "1.4" - apiVersion = "1.4" - freeCompilerArgs += listOf("-Xsuppress-version-warnings", "-Xinline-classes") - } - } -} +configureKotlinCompileTasksGradleCompatibility() publish() diff --git a/compiler/util-klib/build.gradle.kts b/compiler/util-klib/build.gradle.kts index ac23365b417..96b04ec541c 100644 --- a/compiler/util-klib/build.gradle.kts +++ b/compiler/util-klib/build.gradle.kts @@ -18,13 +18,7 @@ sourceSets { "test" { projectDefault() } } -tasks.withType().configureEach { - kotlinOptions { - languageVersion = "1.4" - apiVersion = "1.4" - freeCompilerArgs += listOf("-Xsuppress-version-warnings") - } -} +configureKotlinCompileTasksGradleCompatibility() publish() diff --git a/libraries/tools/kotlin-project-model/build.gradle.kts b/libraries/tools/kotlin-project-model/build.gradle.kts index e2c808af4bd..2b17db14a9f 100644 --- a/libraries/tools/kotlin-project-model/build.gradle.kts +++ b/libraries/tools/kotlin-project-model/build.gradle.kts @@ -24,13 +24,7 @@ projectTest(jUnitMode = JUnitMode.JUnit5) { useJUnitPlatform() } -tasks.withType().configureEach { - kotlinOptions { - languageVersion = "1.4" - apiVersion = "1.4" - freeCompilerArgs += listOf("-Xskip-prerelease-check", "-Xsuppress-version-warnings") - } -} +configureKotlinCompileTasksGradleCompatibility() tasks.named("compileTestFixturesKotlin") { kotlinOptions { diff --git a/libraries/tools/kotlin-tooling-core/build.gradle.kts b/libraries/tools/kotlin-tooling-core/build.gradle.kts index b73f54ab444..7b305f2cdc9 100644 --- a/libraries/tools/kotlin-tooling-core/build.gradle.kts +++ b/libraries/tools/kotlin-tooling-core/build.gradle.kts @@ -9,11 +9,6 @@ sourcesJar() javadocJar() configureKotlinCompileTasksGradleCompatibility() -kotlin.sourceSets.configureEach { - languageSettings.apiVersion = "1.4" - languageSettings.languageVersion = "1.4" -} - dependencies { api(platform(project(":kotlin-gradle-plugins-bom"))) compileOnly(kotlinStdlib()) diff --git a/native/utils/build.gradle.kts b/native/utils/build.gradle.kts index f4ec40fa30b..2d34b75a4cf 100644 --- a/native/utils/build.gradle.kts +++ b/native/utils/build.gradle.kts @@ -22,15 +22,9 @@ sourceSets { "test" { projectDefault() } } -tasks { - withType { - kotlinOptions { - languageVersion = "1.4" - apiVersion = "1.4" - freeCompilerArgs += "-Xsuppress-version-warnings" - } - } +configureKotlinCompileTasksGradleCompatibility() +tasks { withType().configureEach { useJUnitPlatform() }