Skip to content

Commit 75e5747

Browse files
committed
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
1 parent 58020ff commit 75e5747

File tree

6 files changed

+17
-19
lines changed

6 files changed

+17
-19
lines changed

buildSrc/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ ext {
2020
dependencies {
2121
checkstyle "io.spring.javaformat:spring-javaformat-checkstyle:${javaFormatVersion}"
2222
implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
23-
implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:${kotlinVersion}"
2423
implementation "org.gradle:test-retry-gradle-plugin:1.5.6"
2524
implementation "io.spring.javaformat:spring-javaformat-gradle-plugin:${javaFormatVersion}"
2625
implementation "io.spring.nohttp:nohttp-gradle:0.0.11"
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,15 +16,14 @@
1616

1717
package org.springframework.build;
1818

19-
import java.util.ArrayList;
20-
import java.util.List;
21-
2219
import org.gradle.api.Project;
23-
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions;
20+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget;
21+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion;
2422
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile;
2523

2624
/**
2725
* @author Brian Clozel
26+
* @author Sebastien Deleuze
2827
*/
2928
public class KotlinConventions {
3029

@@ -34,15 +33,14 @@ void apply(Project project) {
3433
}
3534

3635
private void configure(KotlinCompile compile) {
37-
KotlinJvmOptions kotlinOptions = compile.getKotlinOptions();
38-
kotlinOptions.setApiVersion("1.7");
39-
kotlinOptions.setLanguageVersion("1.7");
40-
kotlinOptions.setJvmTarget("17");
41-
kotlinOptions.setJavaParameters(true);
42-
kotlinOptions.setAllWarningsAsErrors(true);
43-
List<String> freeCompilerArgs = new ArrayList<>(compile.getKotlinOptions().getFreeCompilerArgs());
44-
freeCompilerArgs.addAll(List.of("-Xsuppress-version-warnings", "-Xjsr305=strict", "-opt-in=kotlin.RequiresOptIn"));
45-
compile.getKotlinOptions().setFreeCompilerArgs(freeCompilerArgs);
36+
compile.compilerOptions(options -> {
37+
options.getApiVersion().set(KotlinVersion.KOTLIN_2_1);
38+
options.getLanguageVersion().set(KotlinVersion.KOTLIN_2_1);
39+
options.getJvmTarget().set(JvmTarget.JVM_17);
40+
options.getJavaParameters().set(true);
41+
options.getAllWarningsAsErrors().set(true);
42+
options.getFreeCompilerArgs().addAll("-Xsuppress-version-warnings", "-Xjsr305=strict", "-opt-in=kotlin.RequiresOptIn");
43+
});
4644
}
4745

4846
}

framework-docs/modules/ROOT/pages/languages/kotlin/requirements.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
= Requirements
33
:page-section-summary-toc: 1
44

5-
Spring Framework supports Kotlin 1.7+ and requires
5+
Spring Framework supports Kotlin 2.1+ and requires
66
https://search.maven.org/artifact/org.jetbrains.kotlin/kotlin-stdlib[`kotlin-stdlib`]
77
and https://search.maven.org/artifact/org.jetbrains.kotlin/kotlin-reflect[`kotlin-reflect`]
88
to be present on the classpath. They are provided by default if you bootstrap a Kotlin project on

framework-platform/framework-platform.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ dependencies {
1818
api(platform("org.assertj:assertj-bom:3.26.3"))
1919
api(platform("org.eclipse.jetty:jetty-bom:12.0.15"))
2020
api(platform("org.eclipse.jetty.ee10:jetty-ee10-bom:12.0.15"))
21-
api(platform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.8.1"))
22-
api(platform("org.jetbrains.kotlinx:kotlinx-serialization-bom:1.6.3"))
21+
api(platform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.9.0"))
22+
api(platform("org.jetbrains.kotlinx:kotlinx-serialization-bom:1.7.3"))
2323
api(platform("org.junit:junit-bom:5.11.3"))
2424
api(platform("org.mockito:mockito-bom:5.14.2"))
2525

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ org.gradle.caching=true
44
org.gradle.jvmargs=-Xmx2048m
55
org.gradle.parallel=true
66

7-
kotlinVersion=1.9.25
7+
kotlinVersion=2.1.0
88

99
kotlin.jvm.target.validation.mode=ignore
1010
kotlin.stdlib.default.dependency=false

spring-context/spring-context.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ dependencies {
4747
testImplementation("org.awaitility:awaitility")
4848
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
4949
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
50+
testImplementation("io.projectreactor:reactor-test")
5051
testImplementation("io.reactivex.rxjava3:rxjava")
5152
testImplementation('io.micrometer:context-propagation')
5253
testImplementation("io.micrometer:micrometer-observation-test")

0 commit comments

Comments
 (0)