From ba9bef6bbfa8364e6b4fd95c383d10a2624a04c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Mon, 23 Jun 2025 17:48:04 +0200 Subject: [PATCH] Upgrade to Kotlin 2.2.0 Kotlin 2.2 is the new baseline for Spring Framework 7.0. -Xannotation-default-target=param-property is specified to avoid warnings when compiling tests or documentation snippets. It is expected to become the default behavior in an upcoming version of Kotlin, see https://youtrack.jetbrains.com/issue/KT-73255 for more details. Closes gh-34453 --- .../java/org/springframework/build/KotlinConventions.java | 7 ++++--- framework-docs/framework-docs.gradle | 1 + .../modules/ROOT/pages/languages/kotlin/requirements.adoc | 2 +- gradle.properties | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/build/KotlinConventions.java b/buildSrc/src/main/java/org/springframework/build/KotlinConventions.java index b3c742a834c..59b2a3f4012 100644 --- a/buildSrc/src/main/java/org/springframework/build/KotlinConventions.java +++ b/buildSrc/src/main/java/org/springframework/build/KotlinConventions.java @@ -34,8 +34,8 @@ public class KotlinConventions { private void configure(KotlinCompile compile) { compile.compilerOptions(options -> { - options.getApiVersion().set(KotlinVersion.KOTLIN_2_1); - options.getLanguageVersion().set(KotlinVersion.KOTLIN_2_1); + options.getApiVersion().set(KotlinVersion.KOTLIN_2_2); + options.getLanguageVersion().set(KotlinVersion.KOTLIN_2_2); options.getJvmTarget().set(JvmTarget.JVM_17); options.getJavaParameters().set(true); options.getAllWarningsAsErrors().set(true); @@ -43,7 +43,8 @@ public class KotlinConventions { "-Xsuppress-version-warnings", "-Xjsr305=strict", // For dependencies using JSR 305 "-opt-in=kotlin.RequiresOptIn", - "-Xjdk-release=17" // Needed due to https://youtrack.jetbrains.com/issue/KT-49746 + "-Xjdk-release=17", // Needed due to https://youtrack.jetbrains.com/issue/KT-49746 + "-Xannotation-default-target=param-property" // Upcoming default, see https://youtrack.jetbrains.com/issue/KT-73255 ); }); } diff --git a/framework-docs/framework-docs.gradle b/framework-docs/framework-docs.gradle index 84527746bd8..b9b6746d7ba 100644 --- a/framework-docs/framework-docs.gradle +++ b/framework-docs/framework-docs.gradle @@ -46,6 +46,7 @@ repositories { // To avoid a redeclaration error with Kotlin compiler tasks.named('compileKotlin', KotlinCompilationTask.class) { javaSources.from = [] + compilerOptions.freeCompilerArgs = [ "-Xannotation-default-target=param-property" ] // Upcoming default, see https://youtrack.jetbrains.com/issue/KT-73255 } dependencies { diff --git a/framework-docs/modules/ROOT/pages/languages/kotlin/requirements.adoc b/framework-docs/modules/ROOT/pages/languages/kotlin/requirements.adoc index fcc26798b54..a1bfc5b9cb4 100644 --- a/framework-docs/modules/ROOT/pages/languages/kotlin/requirements.adoc +++ b/framework-docs/modules/ROOT/pages/languages/kotlin/requirements.adoc @@ -2,7 +2,7 @@ = Requirements :page-section-summary-toc: 1 -Spring Framework supports Kotlin 2.1+ and requires +Spring Framework supports Kotlin 2.2+ and requires https://search.maven.org/artifact/org.jetbrains.kotlin/kotlin-stdlib[`kotlin-stdlib`] and https://search.maven.org/artifact/org.jetbrains.kotlin/kotlin-reflect[`kotlin-reflect`] to be present on the classpath. They are provided by default if you bootstrap a Kotlin project on diff --git a/gradle.properties b/gradle.properties index a50cbe94231..0e4ef3c1412 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.caching=true org.gradle.jvmargs=-Xmx2048m org.gradle.parallel=true -kotlinVersion=2.2.0-RC2 +kotlinVersion=2.2.0 kotlin.jvm.target.validation.mode=ignore kotlin.stdlib.default.dependency=false