From 75e57475ca7bfe3850c81fcf7079a02771f01e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Thu, 5 Dec 2024 11:16:58 +0100 Subject: [PATCH] Upgrade to Kotlin 2.1.0 Spring Framework 7.0 will use a Kotlin 2 baseline, using the latest 2.x release at the time of the release. This commit upgrades Kotlin to 2.1.0, and Kotlin Serialization and Coroutines accordingly. Closes gh-33629 --- buildSrc/build.gradle | 1 - .../build/KotlinConventions.java | 26 +++++++++---------- .../pages/languages/kotlin/requirements.adoc | 2 +- framework-platform/framework-platform.gradle | 4 +-- gradle.properties | 2 +- spring-context/spring-context.gradle | 1 + 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 19d41d438fe..5cba7cf86fb 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -20,7 +20,6 @@ ext { dependencies { checkstyle "io.spring.javaformat:spring-javaformat-checkstyle:${javaFormatVersion}" implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}" - implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:${kotlinVersion}" implementation "org.gradle:test-retry-gradle-plugin:1.5.6" implementation "io.spring.javaformat:spring-javaformat-gradle-plugin:${javaFormatVersion}" implementation "io.spring.nohttp:nohttp-gradle:0.0.11" diff --git a/buildSrc/src/main/java/org/springframework/build/KotlinConventions.java b/buildSrc/src/main/java/org/springframework/build/KotlinConventions.java index 438501d228f..8e381a3b777 100644 --- a/buildSrc/src/main/java/org/springframework/build/KotlinConventions.java +++ b/buildSrc/src/main/java/org/springframework/build/KotlinConventions.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,15 +16,14 @@ package org.springframework.build; -import java.util.ArrayList; -import java.util.List; - import org.gradle.api.Project; -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions; +import org.jetbrains.kotlin.gradle.dsl.JvmTarget; +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion; import org.jetbrains.kotlin.gradle.tasks.KotlinCompile; /** * @author Brian Clozel + * @author Sebastien Deleuze */ public class KotlinConventions { @@ -34,15 +33,14 @@ public class KotlinConventions { } private void configure(KotlinCompile compile) { - KotlinJvmOptions kotlinOptions = compile.getKotlinOptions(); - kotlinOptions.setApiVersion("1.7"); - kotlinOptions.setLanguageVersion("1.7"); - kotlinOptions.setJvmTarget("17"); - kotlinOptions.setJavaParameters(true); - kotlinOptions.setAllWarningsAsErrors(true); - List freeCompilerArgs = new ArrayList<>(compile.getKotlinOptions().getFreeCompilerArgs()); - freeCompilerArgs.addAll(List.of("-Xsuppress-version-warnings", "-Xjsr305=strict", "-opt-in=kotlin.RequiresOptIn")); - compile.getKotlinOptions().setFreeCompilerArgs(freeCompilerArgs); + compile.compilerOptions(options -> { + options.getApiVersion().set(KotlinVersion.KOTLIN_2_1); + options.getLanguageVersion().set(KotlinVersion.KOTLIN_2_1); + options.getJvmTarget().set(JvmTarget.JVM_17); + options.getJavaParameters().set(true); + options.getAllWarningsAsErrors().set(true); + options.getFreeCompilerArgs().addAll("-Xsuppress-version-warnings", "-Xjsr305=strict", "-opt-in=kotlin.RequiresOptIn"); + }); } } diff --git a/framework-docs/modules/ROOT/pages/languages/kotlin/requirements.adoc b/framework-docs/modules/ROOT/pages/languages/kotlin/requirements.adoc index d2b3657d312..fcc26798b54 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 1.7+ and requires +Spring Framework supports Kotlin 2.1+ 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/framework-platform/framework-platform.gradle b/framework-platform/framework-platform.gradle index 4c5779824bd..77bf3dc0164 100644 --- a/framework-platform/framework-platform.gradle +++ b/framework-platform/framework-platform.gradle @@ -18,8 +18,8 @@ dependencies { api(platform("org.assertj:assertj-bom:3.26.3")) api(platform("org.eclipse.jetty:jetty-bom:12.0.15")) api(platform("org.eclipse.jetty.ee10:jetty-ee10-bom:12.0.15")) - api(platform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.8.1")) - api(platform("org.jetbrains.kotlinx:kotlinx-serialization-bom:1.6.3")) + api(platform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.9.0")) + api(platform("org.jetbrains.kotlinx:kotlinx-serialization-bom:1.7.3")) api(platform("org.junit:junit-bom:5.11.3")) api(platform("org.mockito:mockito-bom:5.14.2")) diff --git a/gradle.properties b/gradle.properties index 2353ef8dc47..37459f39dca 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.caching=true org.gradle.jvmargs=-Xmx2048m org.gradle.parallel=true -kotlinVersion=1.9.25 +kotlinVersion=2.1.0 kotlin.jvm.target.validation.mode=ignore kotlin.stdlib.default.dependency=false diff --git a/spring-context/spring-context.gradle b/spring-context/spring-context.gradle index 4a24c9ac41c..31da2964c76 100644 --- a/spring-context/spring-context.gradle +++ b/spring-context/spring-context.gradle @@ -47,6 +47,7 @@ dependencies { testImplementation("org.awaitility:awaitility") testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core") testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor") + testImplementation("io.projectreactor:reactor-test") testImplementation("io.reactivex.rxjava3:rxjava") testImplementation('io.micrometer:context-propagation') testImplementation("io.micrometer:micrometer-observation-test")