Upgrade to Kotlin 2.1.0
This commit upgrades to Kotlin 2.1.0. Two related dependencies have been updated as well: Kotlin Coroutines to 1.10, and Kotlin Serialization to 1.8. As of Kotlin 2, it is no longer possible to have a Java type and a Kotlin type with the same name. As our code samples follow that unfortunate pattern, this commit makes sure that the Kotlin sample code does not depend on any of the Java counterpart and configure the kotlin compilation plugin to ignore Java sources. The minimum version of Gradle is 7.6.4. It bundles a version of Kotlin that cannot compile a Kotlin build script when spring-core, compiled with Kotlin 2.1, is on the classpath. Using Gradle 8.12 to run the DSL tests avoids the problem. Closes gh-45486 Co-authored-by: Andy Wilkinson <andy.wilkinson@broadcom.com>
This commit is contained in:
committed by
Phillip Webb
parent
5ce080f1bb
commit
7035c0fa0a
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
* Copyright 2012-2025 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.
|
||||
@@ -49,7 +49,7 @@ class KotlinPluginAction implements PluginApplicationAction {
|
||||
private void enableJavaParametersOption(Project project) {
|
||||
project.getTasks()
|
||||
.withType(KotlinCompile.class)
|
||||
.configureEach((compile) -> compile.getKotlinOptions().setJavaParameters(true));
|
||||
.configureEach((compile) -> compile.getCompilerOptions().getJavaParameters().set(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2024 the original author or authors.
|
||||
* Copyright 2012-2025 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.
|
||||
@@ -30,7 +30,6 @@ import org.springframework.boot.gradle.testkit.PluginClasspathGradleBuild;
|
||||
import org.springframework.boot.testsupport.gradle.testkit.Dsl;
|
||||
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;
|
||||
import org.springframework.boot.testsupport.gradle.testkit.GradleBuildExtension;
|
||||
import org.springframework.boot.testsupport.gradle.testkit.GradleVersions;
|
||||
|
||||
/**
|
||||
* {@link Extension} that runs {@link TestTemplate templated tests} against the Groovy and
|
||||
@@ -61,8 +60,7 @@ public class GradleMultiDslExtension implements TestTemplateInvocationContextPro
|
||||
|
||||
@Override
|
||||
public List<Extension> getAdditionalExtensions() {
|
||||
GradleBuild gradleBuild = new PluginClasspathGradleBuild(this.dsl)
|
||||
.gradleVersion(GradleVersions.minimumCompatible());
|
||||
GradleBuild gradleBuild = new PluginClasspathGradleBuild(this.dsl);
|
||||
return Arrays.asList(new GradleBuildFieldSetter(gradleBuild), new GradleBuildExtension());
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
@ExtendWith(GradleBuildExtension.class)
|
||||
class KotlinPluginActionIntegrationTests {
|
||||
|
||||
GradleBuild gradleBuild = new PluginClasspathGradleBuild();
|
||||
GradleBuild gradleBuild = new PluginClasspathGradleBuild().kotlin();
|
||||
|
||||
@Test
|
||||
void noKotlinVersionPropertyWithoutKotlinPlugin() {
|
||||
@@ -87,7 +87,7 @@ class KotlinPluginActionIntegrationTests {
|
||||
configured.add(line.substring("Configuring :".length()));
|
||||
}
|
||||
}
|
||||
assertThat(configured).containsExactlyInAnyOrder("help", "compileJava", "clean");
|
||||
assertThat(configured).containsExactlyInAnyOrder("help", "clean");
|
||||
}
|
||||
|
||||
private void expectConfigurationCacheRequestedDeprecationWarning() {
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.boot.gradle.testkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
@@ -55,6 +55,8 @@ import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;
|
||||
*/
|
||||
public class PluginClasspathGradleBuild extends GradleBuild {
|
||||
|
||||
private boolean kotlin = false;
|
||||
|
||||
public PluginClasspathGradleBuild() {
|
||||
super();
|
||||
}
|
||||
@@ -63,35 +65,53 @@ public class PluginClasspathGradleBuild extends GradleBuild {
|
||||
super(dsl);
|
||||
}
|
||||
|
||||
public PluginClasspathGradleBuild kotlin() {
|
||||
this.kotlin = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GradleRunner prepareRunner(String... arguments) throws IOException {
|
||||
return super.prepareRunner(arguments).withPluginClasspath(pluginClasspath());
|
||||
}
|
||||
|
||||
private List<File> pluginClasspath() {
|
||||
return Arrays.asList(new File("bin/main"), new File("build/classes/java/main"),
|
||||
new File("build/resources/main"), new File(pathOfJarContaining(LaunchScript.class)),
|
||||
new File(pathOfJarContaining(ClassVisitor.class)),
|
||||
new File(pathOfJarContaining(DependencyManagementPlugin.class)),
|
||||
new File(pathOfJarContaining("org.jetbrains.kotlin.cli.common.PropertiesKt")),
|
||||
new File(pathOfJarContaining(KotlinPlatformJvmPlugin.class)),
|
||||
new File(pathOfJarContaining(KotlinProject.class)),
|
||||
new File(pathOfJarContaining(KotlinToolingVersion.class)),
|
||||
new File(pathOfJarContaining("org.jetbrains.kotlin.daemon.client.KotlinCompilerClient")),
|
||||
new File(pathOfJarContaining(KotlinCompilerPluginSupportPlugin.class)),
|
||||
new File(pathOfJarContaining(LanguageSettings.class)),
|
||||
new File(pathOfJarContaining(ArchiveEntry.class)), new File(pathOfJarContaining(BuildRequest.class)),
|
||||
new File(pathOfJarContaining(HttpClientConnectionManager.class)),
|
||||
new File(pathOfJarContaining(HttpRequest.class)),
|
||||
new File(pathOfJarContaining(HttpVersionPolicy.class)), new File(pathOfJarContaining(Module.class)),
|
||||
new File(pathOfJarContaining(Versioned.class)),
|
||||
new File(pathOfJarContaining(ParameterNamesModule.class)),
|
||||
new File(pathOfJarContaining("com.github.openjson.JSONObject")),
|
||||
new File(pathOfJarContaining(JsonView.class)), new File(pathOfJarContaining(Platform.class)),
|
||||
new File(pathOfJarContaining(Toml.class)), new File(pathOfJarContaining(Lexer.class)),
|
||||
new File(pathOfJarContaining("org.graalvm.buildtools.gradle.NativeImagePlugin")),
|
||||
new File(pathOfJarContaining("org.graalvm.reachability.GraalVMReachabilityMetadataRepository")),
|
||||
new File(pathOfJarContaining("org.graalvm.buildtools.utils.SharedConstants")));
|
||||
List<File> classpath = new ArrayList<>();
|
||||
classpath.add(new File("bin/main"));
|
||||
classpath.add(new File("build/classes/java/main"));
|
||||
classpath.add(new File("build/resources/main"));
|
||||
classpath.add(new File(pathOfJarContaining(LaunchScript.class)));
|
||||
classpath.add(new File(pathOfJarContaining(ClassVisitor.class)));
|
||||
classpath.add(new File(pathOfJarContaining(DependencyManagementPlugin.class)));
|
||||
if (this.kotlin) {
|
||||
classpath.add(new File(pathOfJarContaining("org.jetbrains.kotlin.cli.common.PropertiesKt")));
|
||||
classpath.add(new File(pathOfJarContaining(KotlinPlatformJvmPlugin.class)));
|
||||
classpath.add(new File(pathOfJarContaining(KotlinProject.class)));
|
||||
classpath.add(new File(pathOfJarContaining(KotlinToolingVersion.class)));
|
||||
classpath.add(new File(pathOfJarContaining("org.jetbrains.kotlin.build.report.metrics.BuildTime")));
|
||||
classpath.add(new File(pathOfJarContaining("org.jetbrains.kotlin.buildtools.api.CompilationService")));
|
||||
classpath.add(new File(pathOfJarContaining("org.jetbrains.kotlin.daemon.client.KotlinCompilerClient")));
|
||||
classpath.add(new File(pathOfJarContaining("org.jetbrains.kotlin.konan.library.KonanLibrary")));
|
||||
classpath.add(new File(pathOfJarContaining(KotlinCompilerPluginSupportPlugin.class)));
|
||||
classpath.add(new File(pathOfJarContaining(LanguageSettings.class)));
|
||||
}
|
||||
classpath.add(new File(pathOfJarContaining(ArchiveEntry.class)));
|
||||
classpath.add(new File(pathOfJarContaining(BuildRequest.class)));
|
||||
classpath.add(new File(pathOfJarContaining(HttpClientConnectionManager.class)));
|
||||
classpath.add(new File(pathOfJarContaining(HttpRequest.class)));
|
||||
classpath.add(new File(pathOfJarContaining(HttpVersionPolicy.class)));
|
||||
classpath.add(new File(pathOfJarContaining(Module.class)));
|
||||
classpath.add(new File(pathOfJarContaining(Versioned.class)));
|
||||
classpath.add(new File(pathOfJarContaining(ParameterNamesModule.class)));
|
||||
classpath.add(new File(pathOfJarContaining("com.github.openjson.JSONObject")));
|
||||
classpath.add(new File(pathOfJarContaining(JsonView.class)));
|
||||
classpath.add(new File(pathOfJarContaining(Platform.class)));
|
||||
classpath.add(new File(pathOfJarContaining(Toml.class)));
|
||||
classpath.add(new File(pathOfJarContaining(Lexer.class)));
|
||||
classpath.add(new File(pathOfJarContaining("org.graalvm.buildtools.gradle.NativeImagePlugin")));
|
||||
classpath.add(new File(pathOfJarContaining("org.graalvm.reachability.GraalVMReachabilityMetadataRepository")));
|
||||
classpath.add(new File(pathOfJarContaining("org.graalvm.buildtools.utils.SharedConstants")));
|
||||
return classpath;
|
||||
}
|
||||
|
||||
private String pathOfJarContaining(String className) {
|
||||
|
||||
@@ -4,16 +4,18 @@ plugins {
|
||||
|
||||
apply plugin: 'org.jetbrains.kotlin.jvm'
|
||||
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
tasks.withType(KotlinCompile) {
|
||||
kotlinOptions.javaParameters = false
|
||||
compilerOptions {
|
||||
javaParameters = false
|
||||
}
|
||||
}
|
||||
|
||||
task('kotlinCompileTasksJavaParameters') {
|
||||
doFirst {
|
||||
tasks.withType(KotlinCompile) {
|
||||
println "${name} java parameters: ${kotlinOptions.javaParameters}"
|
||||
println "${name} java parameters: ${compilerOptions.javaParameters.get()}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,12 @@ plugins {
|
||||
|
||||
apply plugin: 'org.jetbrains.kotlin.jvm'
|
||||
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
task('kotlinCompileTasksJavaParameters') {
|
||||
doFirst {
|
||||
tasks.withType(KotlinCompile) {
|
||||
println "${name} java parameters: ${kotlinOptions.javaParameters}"
|
||||
println "${name} java parameters: ${compilerOptions.javaParameters.get()}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user