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:
Stéphane Nicoll 2024-12-12 17:47:24 +01:00 committed by Phillip Webb
parent 5ce080f1bb
commit 7035c0fa0a
30 changed files with 374 additions and 69 deletions

1
.gitignore vendored
View File

@ -41,3 +41,4 @@ secrets.yml
.sts4-cache .sts4-cache
.git-hooks/ .git-hooks/
node_modules node_modules
/.kotlin/

View File

@ -42,7 +42,6 @@ dependencies {
implementation("org.apache.maven:maven-artifact:${mavenVersion}") implementation("org.apache.maven:maven-artifact:${mavenVersion}")
implementation("org.antora:gradle-antora-plugin:1.0.0") implementation("org.antora:gradle-antora-plugin:1.0.0")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}") implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:${kotlinVersion}")
implementation("org.springframework:spring-context") implementation("org.springframework:spring-context")
implementation("org.springframework:spring-core") implementation("org.springframework:spring-core")
implementation("org.springframework:spring-web") implementation("org.springframework:spring-web")

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,15 +17,15 @@
package org.springframework.boot.build; package org.springframework.boot.build;
import java.net.URI; import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import dev.adamko.dokkatoo.DokkatooExtension; import dev.adamko.dokkatoo.DokkatooExtension;
import dev.adamko.dokkatoo.formats.DokkatooHtmlPlugin; import dev.adamko.dokkatoo.formats.DokkatooHtmlPlugin;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer; import org.gradle.api.tasks.SourceSetContainer;
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions; import org.jetbrains.kotlin.gradle.dsl.JvmTarget;
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions;
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion;
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile; import org.jetbrains.kotlin.gradle.tasks.KotlinCompile;
/** /**
@ -56,14 +56,12 @@ class KotlinConventions {
} }
private void configure(KotlinCompile compile) { private void configure(KotlinCompile compile) {
KotlinJvmOptions kotlinOptions = compile.getKotlinOptions(); KotlinJvmCompilerOptions compilerOptions = compile.getCompilerOptions();
kotlinOptions.setApiVersion("1.7"); compilerOptions.getApiVersion().set(KotlinVersion.KOTLIN_2_1);
kotlinOptions.setLanguageVersion("1.7"); compilerOptions.getLanguageVersion().set(KotlinVersion.KOTLIN_2_1);
kotlinOptions.setJvmTarget("17"); compilerOptions.getJvmTarget().set(JvmTarget.JVM_17);
kotlinOptions.setAllWarningsAsErrors(true); compilerOptions.getAllWarningsAsErrors().set(true);
List<String> freeCompilerArgs = new ArrayList<>(kotlinOptions.getFreeCompilerArgs()); compilerOptions.getFreeCompilerArgs().addAll("-Xsuppress-version-warnings");
freeCompilerArgs.add("-Xsuppress-version-warnings");
kotlinOptions.setFreeCompilerArgs(freeCompilerArgs);
} }
private void configureDokkatoo(Project project) { private void configureDokkatoo(Project project) {

View File

@ -14,7 +14,7 @@ hamcrestVersion=3.0
jacksonVersion=2.18.4 jacksonVersion=2.18.4
javaFormatVersion=0.0.43 javaFormatVersion=0.0.43
junitJupiterVersion=5.12.2 junitJupiterVersion=5.12.2
kotlinVersion=1.9.25 kotlinVersion=2.1.0
mavenVersion=3.9.4 mavenVersion=3.9.4
mockitoVersion=5.17.0 mockitoVersion=5.17.0
nativeBuildToolsVersion=0.10.6 nativeBuildToolsVersion=0.10.6

View File

@ -1174,10 +1174,6 @@ bom {
} }
} }
library("Kotlin", "${kotlinVersion}") { library("Kotlin", "${kotlinVersion}") {
prohibit {
versionRange "[2.0.0-Beta1,)"
because "it exceeds our baseline"
}
group("org.jetbrains.kotlin") { group("org.jetbrains.kotlin") {
bom("kotlin-bom") bom("kotlin-bom")
plugins = [ plugins = [
@ -1190,11 +1186,7 @@ bom {
releaseNotes("https://github.com/JetBrains/kotlin/releases/tag/v{version}") releaseNotes("https://github.com/JetBrains/kotlin/releases/tag/v{version}")
} }
} }
library("Kotlin Coroutines", "1.8.1") { library("Kotlin Coroutines", "1.10.1") {
prohibit {
versionRange "[1.9.0-RC,)"
because "it requires Kotlin 2"
}
group("org.jetbrains.kotlinx") { group("org.jetbrains.kotlinx") {
bom("kotlinx-coroutines-bom") bom("kotlinx-coroutines-bom")
} }
@ -1203,11 +1195,7 @@ bom {
releaseNotes("https://github.com/Kotlin/kotlinx.coroutines/releases/tag/{version}") releaseNotes("https://github.com/Kotlin/kotlinx.coroutines/releases/tag/{version}")
} }
} }
library("Kotlin Serialization", "1.6.3") { library("Kotlin Serialization", "1.8.0") {
prohibit {
versionRange "[1.7.0-RC,)"
because "it requires Kotlin 2"
}
group("org.jetbrains.kotlinx") { group("org.jetbrains.kotlinx") {
bom("kotlinx-serialization-bom") bom("kotlinx-serialization-bom")
} }

View File

@ -1,3 +1,4 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import org.springframework.boot.build.docs.ConfigureJavadocLinks import org.springframework.boot.build.docs.ConfigureJavadocLinks
plugins { plugins {
@ -46,6 +47,11 @@ sourcesJar {
enabled = false enabled = false
} }
// To avoid a redeclaration error with Kotlin compiler
tasks.named('compileKotlin', KotlinCompilationTask.class) {
javaSources.from = []
}
plugins.withType(EclipsePlugin) { plugins.withType(EclipsePlugin) {
eclipse.classpath { classpath -> eclipse.classpath { classpath ->
classpath.plusConfigurations.add(configurations.getByName(sourceSets.main.runtimeClasspathConfigurationName)) classpath.plusConfigurations.add(configurations.getByName(sourceSets.main.runtimeClasspathConfigurationName))

View File

@ -15,7 +15,7 @@ Feel free to join the #spring channel of https://slack.kotlinlang.org/[Kotlin Sl
[[features.kotlin.requirements]] [[features.kotlin.requirements]]
== Requirements == Requirements
Spring Boot requires at least Kotlin 1.7.x and manages a suitable Kotlin version through dependency management. Spring Boot requires at least Kotlin 2.1.x and manages a suitable Kotlin version through dependency management.
To use Kotlin, `org.jetbrains.kotlin:kotlin-stdlib` and `org.jetbrains.kotlin:kotlin-reflect` must be present on the classpath. To use Kotlin, `org.jetbrains.kotlin:kotlin-stdlib` and `org.jetbrains.kotlin:kotlin-reflect` must be present on the classpath.
The `kotlin-stdlib` variants `kotlin-stdlib-jdk7` and `kotlin-stdlib-jdk8` can also be used. The `kotlin-stdlib` variants `kotlin-stdlib-jdk7` and `kotlin-stdlib-jdk8` can also be used.

View File

@ -0,0 +1,19 @@
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.data.nosql.cassandra.connecting
class User

View File

@ -0,0 +1,23 @@
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.features.externalconfig.typesafeconfigurationproperties.usingannotatedtypes
class Server(remoteAddress: Any?) {
fun start() {
}
}

View File

@ -0,0 +1,19 @@
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.features.springapplication.applicationavailability.managing
class CacheCompletelyBrokenException: RuntimeException()

View File

@ -0,0 +1,20 @@
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.features.testcontainers.atdevelopmenttime.importingcontainerdeclarations
class MyContainers {
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,6 @@
package org.springframework.boot.docs.features.testcontainers.atdevelopmenttime.importingcontainerdeclarations package org.springframework.boot.docs.features.testcontainers.atdevelopmenttime.importingcontainerdeclarations
import org.springframework.boot.docs.features.devservices.testcontainers.atdevelopmenttime.importingcontainerdeclarations.MyContainers
import org.springframework.boot.test.context.TestConfiguration import org.springframework.boot.test.context.TestConfiguration
import org.springframework.boot.testcontainers.context.ImportTestcontainers import org.springframework.boot.testcontainers.context.ImportTestcontainers

View File

@ -0,0 +1,20 @@
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.packaging.nativeimage.advanced.nestedconfigurationproperties
class Nested {
}

View File

@ -0,0 +1,20 @@
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.using.springbeansanddependencyinjection.multipleconstructors
interface AccountService {
}

View File

@ -0,0 +1,20 @@
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.using.springbeansanddependencyinjection.multipleconstructors
interface RiskAssessor {
}

View File

@ -0,0 +1,20 @@
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.using.springbeansanddependencyinjection.singleconstructor
interface AccountService {
}

View File

@ -0,0 +1,20 @@
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.using.springbeansanddependencyinjection.singleconstructor
interface RiskAssessor {
}

View File

@ -0,0 +1,19 @@
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.using.usingthespringbootapplicationannotation.individualannotations
class AnotherConfiguration

View File

@ -0,0 +1,19 @@
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.using.usingthespringbootapplicationannotation.individualannotations
class SomeConfiguration

View File

@ -0,0 +1,19 @@
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.web.servlet.springmvc.errorhandling
class MyErrorBody(value: Int, message: String?)

View File

@ -0,0 +1,19 @@
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.web.servlet.springmvc.errorhandling
class MyException: RuntimeException()

View File

@ -0,0 +1,19 @@
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.web.servlet.springmvc.errorhandling
class SomeController

View File

@ -0,0 +1,19 @@
/*
* Copyright 2012-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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.web.servlet.springmvc.errorhandling.errorpageswithoutspringmvc
class SomeController

View File

@ -54,7 +54,6 @@ dependencies {
testImplementation("org.assertj:assertj-core") testImplementation("org.assertj:assertj-core")
testImplementation("org.graalvm.buildtools:native-gradle-plugin") testImplementation("org.graalvm.buildtools:native-gradle-plugin")
testImplementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") testImplementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlinVersion")
testImplementation("org.jetbrains.kotlin:kotlin-compiler-runner:$kotlinVersion") testImplementation("org.jetbrains.kotlin:kotlin-compiler-runner:$kotlinVersion")
testImplementation("org.jetbrains.kotlin:kotlin-daemon-client:$kotlinVersion") testImplementation("org.jetbrains.kotlin:kotlin-daemon-client:$kotlinVersion")
testImplementation("org.junit.jupiter:junit-jupiter") testImplementation("org.junit.jupiter:junit-jupiter")

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { private void enableJavaParametersOption(Project project) {
project.getTasks() project.getTasks()
.withType(KotlinCompile.class) .withType(KotlinCompile.class)
.configureEach((compile) -> compile.getKotlinOptions().setJavaParameters(true)); .configureEach((compile) -> compile.getCompilerOptions().getJavaParameters().set(true));
} }
@Override @Override

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.Dsl;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuild; import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;
import org.springframework.boot.testsupport.gradle.testkit.GradleBuildExtension; 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 * {@link Extension} that runs {@link TestTemplate templated tests} against the Groovy and
@ -61,8 +60,7 @@ public class GradleMultiDslExtension implements TestTemplateInvocationContextPro
@Override @Override
public List<Extension> getAdditionalExtensions() { public List<Extension> getAdditionalExtensions() {
GradleBuild gradleBuild = new PluginClasspathGradleBuild(this.dsl) GradleBuild gradleBuild = new PluginClasspathGradleBuild(this.dsl);
.gradleVersion(GradleVersions.minimumCompatible());
return Arrays.asList(new GradleBuildFieldSetter(gradleBuild), new GradleBuildExtension()); return Arrays.asList(new GradleBuildFieldSetter(gradleBuild), new GradleBuildExtension());
} }

View File

@ -43,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@ExtendWith(GradleBuildExtension.class) @ExtendWith(GradleBuildExtension.class)
class KotlinPluginActionIntegrationTests { class KotlinPluginActionIntegrationTests {
GradleBuild gradleBuild = new PluginClasspathGradleBuild(); GradleBuild gradleBuild = new PluginClasspathGradleBuild().kotlin();
@Test @Test
void noKotlinVersionPropertyWithoutKotlinPlugin() { void noKotlinVersionPropertyWithoutKotlinPlugin() {
@ -87,7 +87,7 @@ class KotlinPluginActionIntegrationTests {
configured.add(line.substring("Configuring :".length())); configured.add(line.substring("Configuring :".length()));
} }
} }
assertThat(configured).containsExactlyInAnyOrder("help", "compileJava", "clean"); assertThat(configured).containsExactlyInAnyOrder("help", "clean");
} }
private void expectConfigurationCacheRequestedDeprecationWarning() { private void expectConfigurationCacheRequestedDeprecationWarning() {

View File

@ -18,7 +18,7 @@ package org.springframework.boot.gradle.testkit;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.fasterxml.jackson.annotation.JsonView; import com.fasterxml.jackson.annotation.JsonView;
@ -55,6 +55,8 @@ import org.springframework.boot.testsupport.gradle.testkit.GradleBuild;
*/ */
public class PluginClasspathGradleBuild extends GradleBuild { public class PluginClasspathGradleBuild extends GradleBuild {
private boolean kotlin = false;
public PluginClasspathGradleBuild() { public PluginClasspathGradleBuild() {
super(); super();
} }
@ -63,35 +65,53 @@ public class PluginClasspathGradleBuild extends GradleBuild {
super(dsl); super(dsl);
} }
public PluginClasspathGradleBuild kotlin() {
this.kotlin = true;
return this;
}
@Override @Override
public GradleRunner prepareRunner(String... arguments) throws IOException { public GradleRunner prepareRunner(String... arguments) throws IOException {
return super.prepareRunner(arguments).withPluginClasspath(pluginClasspath()); return super.prepareRunner(arguments).withPluginClasspath(pluginClasspath());
} }
private List<File> pluginClasspath() { private List<File> pluginClasspath() {
return Arrays.asList(new File("bin/main"), new File("build/classes/java/main"), List<File> classpath = new ArrayList<>();
new File("build/resources/main"), new File(pathOfJarContaining(LaunchScript.class)), classpath.add(new File("bin/main"));
new File(pathOfJarContaining(ClassVisitor.class)), classpath.add(new File("build/classes/java/main"));
new File(pathOfJarContaining(DependencyManagementPlugin.class)), classpath.add(new File("build/resources/main"));
new File(pathOfJarContaining("org.jetbrains.kotlin.cli.common.PropertiesKt")), classpath.add(new File(pathOfJarContaining(LaunchScript.class)));
new File(pathOfJarContaining(KotlinPlatformJvmPlugin.class)), classpath.add(new File(pathOfJarContaining(ClassVisitor.class)));
new File(pathOfJarContaining(KotlinProject.class)), classpath.add(new File(pathOfJarContaining(DependencyManagementPlugin.class)));
new File(pathOfJarContaining(KotlinToolingVersion.class)), if (this.kotlin) {
new File(pathOfJarContaining("org.jetbrains.kotlin.daemon.client.KotlinCompilerClient")), classpath.add(new File(pathOfJarContaining("org.jetbrains.kotlin.cli.common.PropertiesKt")));
new File(pathOfJarContaining(KotlinCompilerPluginSupportPlugin.class)), classpath.add(new File(pathOfJarContaining(KotlinPlatformJvmPlugin.class)));
new File(pathOfJarContaining(LanguageSettings.class)), classpath.add(new File(pathOfJarContaining(KotlinProject.class)));
new File(pathOfJarContaining(ArchiveEntry.class)), new File(pathOfJarContaining(BuildRequest.class)), classpath.add(new File(pathOfJarContaining(KotlinToolingVersion.class)));
new File(pathOfJarContaining(HttpClientConnectionManager.class)), classpath.add(new File(pathOfJarContaining("org.jetbrains.kotlin.build.report.metrics.BuildTime")));
new File(pathOfJarContaining(HttpRequest.class)), classpath.add(new File(pathOfJarContaining("org.jetbrains.kotlin.buildtools.api.CompilationService")));
new File(pathOfJarContaining(HttpVersionPolicy.class)), new File(pathOfJarContaining(Module.class)), classpath.add(new File(pathOfJarContaining("org.jetbrains.kotlin.daemon.client.KotlinCompilerClient")));
new File(pathOfJarContaining(Versioned.class)), classpath.add(new File(pathOfJarContaining("org.jetbrains.kotlin.konan.library.KonanLibrary")));
new File(pathOfJarContaining(ParameterNamesModule.class)), classpath.add(new File(pathOfJarContaining(KotlinCompilerPluginSupportPlugin.class)));
new File(pathOfJarContaining("com.github.openjson.JSONObject")), classpath.add(new File(pathOfJarContaining(LanguageSettings.class)));
new File(pathOfJarContaining(JsonView.class)), new File(pathOfJarContaining(Platform.class)), }
new File(pathOfJarContaining(Toml.class)), new File(pathOfJarContaining(Lexer.class)), classpath.add(new File(pathOfJarContaining(ArchiveEntry.class)));
new File(pathOfJarContaining("org.graalvm.buildtools.gradle.NativeImagePlugin")), classpath.add(new File(pathOfJarContaining(BuildRequest.class)));
new File(pathOfJarContaining("org.graalvm.reachability.GraalVMReachabilityMetadataRepository")), classpath.add(new File(pathOfJarContaining(HttpClientConnectionManager.class)));
new File(pathOfJarContaining("org.graalvm.buildtools.utils.SharedConstants"))); 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) { private String pathOfJarContaining(String className) {

View File

@ -4,16 +4,18 @@ plugins {
apply plugin: 'org.jetbrains.kotlin.jvm' apply plugin: 'org.jetbrains.kotlin.jvm'
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
tasks.withType(KotlinCompile) { tasks.withType(KotlinCompile) {
kotlinOptions.javaParameters = false compilerOptions {
javaParameters = false
}
} }
task('kotlinCompileTasksJavaParameters') { task('kotlinCompileTasksJavaParameters') {
doFirst { doFirst {
tasks.withType(KotlinCompile) { tasks.withType(KotlinCompile) {
println "${name} java parameters: ${kotlinOptions.javaParameters}" println "${name} java parameters: ${compilerOptions.javaParameters.get()}"
} }
} }
} }

View File

@ -4,12 +4,12 @@ plugins {
apply plugin: 'org.jetbrains.kotlin.jvm' apply plugin: 'org.jetbrains.kotlin.jvm'
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
task('kotlinCompileTasksJavaParameters') { task('kotlinCompileTasksJavaParameters') {
doFirst { doFirst {
tasks.withType(KotlinCompile) { tasks.withType(KotlinCompile) {
println "${name} java parameters: ${kotlinOptions.javaParameters}" println "${name} java parameters: ${compilerOptions.javaParameters.get()}"
} }
} }
} }