diff --git a/.gitignore b/.gitignore index 1198c2da875..d5e93a54c62 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ secrets.yml .sts4-cache .git-hooks/ node_modules +/.kotlin/ diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 1fa9d1e229f..b8e4f56fe1a 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -42,7 +42,6 @@ dependencies { implementation("org.apache.maven:maven-artifact:${mavenVersion}") implementation("org.antora:gradle-antora-plugin:1.0.0") 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-core") implementation("org.springframework:spring-web") diff --git a/buildSrc/src/main/java/org/springframework/boot/build/KotlinConventions.java b/buildSrc/src/main/java/org/springframework/boot/build/KotlinConventions.java index 32b38af396d..e59d4e2eba9 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/KotlinConventions.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/KotlinConventions.java @@ -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. @@ -17,15 +17,15 @@ package org.springframework.boot.build; import java.net.URI; -import java.util.ArrayList; -import java.util.List; import dev.adamko.dokkatoo.DokkatooExtension; import dev.adamko.dokkatoo.formats.DokkatooHtmlPlugin; import org.gradle.api.Project; import org.gradle.api.tasks.SourceSet; 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; /** @@ -56,14 +56,12 @@ class KotlinConventions { } private void configure(KotlinCompile compile) { - KotlinJvmOptions kotlinOptions = compile.getKotlinOptions(); - kotlinOptions.setApiVersion("1.7"); - kotlinOptions.setLanguageVersion("1.7"); - kotlinOptions.setJvmTarget("17"); - kotlinOptions.setAllWarningsAsErrors(true); - List freeCompilerArgs = new ArrayList<>(kotlinOptions.getFreeCompilerArgs()); - freeCompilerArgs.add("-Xsuppress-version-warnings"); - kotlinOptions.setFreeCompilerArgs(freeCompilerArgs); + KotlinJvmCompilerOptions compilerOptions = compile.getCompilerOptions(); + compilerOptions.getApiVersion().set(KotlinVersion.KOTLIN_2_1); + compilerOptions.getLanguageVersion().set(KotlinVersion.KOTLIN_2_1); + compilerOptions.getJvmTarget().set(JvmTarget.JVM_17); + compilerOptions.getAllWarningsAsErrors().set(true); + compilerOptions.getFreeCompilerArgs().addAll("-Xsuppress-version-warnings"); } private void configureDokkatoo(Project project) { diff --git a/gradle.properties b/gradle.properties index 655afb59467..856aaca8bfc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ hamcrestVersion=3.0 jacksonVersion=2.18.4 javaFormatVersion=0.0.43 junitJupiterVersion=5.12.2 -kotlinVersion=1.9.25 +kotlinVersion=2.1.0 mavenVersion=3.9.4 mockitoVersion=5.17.0 nativeBuildToolsVersion=0.10.6 diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index bf50335d889..94daa024961 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -1174,10 +1174,6 @@ bom { } } library("Kotlin", "${kotlinVersion}") { - prohibit { - versionRange "[2.0.0-Beta1,)" - because "it exceeds our baseline" - } group("org.jetbrains.kotlin") { bom("kotlin-bom") plugins = [ @@ -1190,11 +1186,7 @@ bom { releaseNotes("https://github.com/JetBrains/kotlin/releases/tag/v{version}") } } - library("Kotlin Coroutines", "1.8.1") { - prohibit { - versionRange "[1.9.0-RC,)" - because "it requires Kotlin 2" - } + library("Kotlin Coroutines", "1.10.1") { group("org.jetbrains.kotlinx") { bom("kotlinx-coroutines-bom") } @@ -1203,11 +1195,7 @@ bom { releaseNotes("https://github.com/Kotlin/kotlinx.coroutines/releases/tag/{version}") } } - library("Kotlin Serialization", "1.6.3") { - prohibit { - versionRange "[1.7.0-RC,)" - because "it requires Kotlin 2" - } + library("Kotlin Serialization", "1.8.0") { group("org.jetbrains.kotlinx") { bom("kotlinx-serialization-bom") } diff --git a/spring-boot-project/spring-boot-docs/build.gradle b/spring-boot-project/spring-boot-docs/build.gradle index 98d4eb5246a..f2e221b018c 100644 --- a/spring-boot-project/spring-boot-docs/build.gradle +++ b/spring-boot-project/spring-boot-docs/build.gradle @@ -1,3 +1,4 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask import org.springframework.boot.build.docs.ConfigureJavadocLinks plugins { @@ -46,6 +47,11 @@ sourcesJar { enabled = false } +// To avoid a redeclaration error with Kotlin compiler +tasks.named('compileKotlin', KotlinCompilationTask.class) { + javaSources.from = [] +} + plugins.withType(EclipsePlugin) { eclipse.classpath { classpath -> classpath.plusConfigurations.add(configurations.getByName(sourceSets.main.runtimeClasspathConfigurationName)) diff --git a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/kotlin.adoc b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/kotlin.adoc index 386903075b3..fdbf0c17487 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/kotlin.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/reference/pages/features/kotlin.adoc @@ -15,7 +15,7 @@ Feel free to join the #spring channel of https://slack.kotlinlang.org/[Kotlin Sl [[features.kotlin.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. The `kotlin-stdlib` variants `kotlin-stdlib-jdk7` and `kotlin-stdlib-jdk8` can also be used. diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/data/nosql/cassandra/connecting/User.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/data/nosql/cassandra/connecting/User.kt new file mode 100644 index 00000000000..44bb6d26650 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/data/nosql/cassandra/connecting/User.kt @@ -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 diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/externalconfig/typesafeconfigurationproperties/usingannotatedtypes/Server.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/externalconfig/typesafeconfigurationproperties/usingannotatedtypes/Server.kt new file mode 100644 index 00000000000..531b1673e59 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/externalconfig/typesafeconfigurationproperties/usingannotatedtypes/Server.kt @@ -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() { + + } +} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/springapplication/applicationavailability/managing/CacheCompletelyBrokenException.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/springapplication/applicationavailability/managing/CacheCompletelyBrokenException.kt new file mode 100644 index 00000000000..af9d08188cf --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/springapplication/applicationavailability/managing/CacheCompletelyBrokenException.kt @@ -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() \ No newline at end of file diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testcontainers/atdevelopmenttime/importingcontainerdeclarations/MyContainers.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testcontainers/atdevelopmenttime/importingcontainerdeclarations/MyContainers.kt new file mode 100644 index 00000000000..00accc529a2 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testcontainers/atdevelopmenttime/importingcontainerdeclarations/MyContainers.kt @@ -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 { +} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testcontainers/atdevelopmenttime/importingcontainerdeclarations/MyContainersConfiguration.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testcontainers/atdevelopmenttime/importingcontainerdeclarations/MyContainersConfiguration.kt index 9c1776c0a4d..813d0388b6a 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testcontainers/atdevelopmenttime/importingcontainerdeclarations/MyContainersConfiguration.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/features/testcontainers/atdevelopmenttime/importingcontainerdeclarations/MyContainersConfiguration.kt @@ -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"); * 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 -import org.springframework.boot.docs.features.devservices.testcontainers.atdevelopmenttime.importingcontainerdeclarations.MyContainers import org.springframework.boot.test.context.TestConfiguration import org.springframework.boot.testcontainers.context.ImportTestcontainers diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/packaging/nativeimage/advanced/nestedconfigurationproperties/Nested.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/packaging/nativeimage/advanced/nestedconfigurationproperties/Nested.kt new file mode 100644 index 00000000000..eb05cd77f0c --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/packaging/nativeimage/advanced/nestedconfigurationproperties/Nested.kt @@ -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 { +} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/AccountService.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/AccountService.kt new file mode 100644 index 00000000000..26eb0e3f52d --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/AccountService.kt @@ -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 { +} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/RiskAssessor.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/RiskAssessor.kt new file mode 100644 index 00000000000..a74c763191d --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/springbeansanddependencyinjection/multipleconstructors/RiskAssessor.kt @@ -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 { +} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/AccountService.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/AccountService.kt new file mode 100644 index 00000000000..c68b911ee57 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/AccountService.kt @@ -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 { +} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/RiskAssessor.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/RiskAssessor.kt new file mode 100644 index 00000000000..2778983f520 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/springbeansanddependencyinjection/singleconstructor/RiskAssessor.kt @@ -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 { +} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/AnotherConfiguration.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/AnotherConfiguration.kt new file mode 100644 index 00000000000..4a541ab9db8 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/AnotherConfiguration.kt @@ -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 \ No newline at end of file diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/SomeConfiguration.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/SomeConfiguration.kt new file mode 100644 index 00000000000..8ab987f6ee7 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/using/usingthespringbootapplicationannotation/individualannotations/SomeConfiguration.kt @@ -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 \ No newline at end of file diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/MyErrorBody.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/MyErrorBody.kt new file mode 100644 index 00000000000..52116a7f9b4 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/MyErrorBody.kt @@ -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?) \ No newline at end of file diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/MyException.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/MyException.kt new file mode 100644 index 00000000000..e01f2fa7348 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/MyException.kt @@ -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() \ No newline at end of file diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/SomeController.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/SomeController.kt new file mode 100644 index 00000000000..7b6ccadae1c --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/SomeController.kt @@ -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 \ No newline at end of file diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/errorpageswithoutspringmvc/SomeController.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/errorpageswithoutspringmvc/SomeController.kt new file mode 100644 index 00000000000..24102841856 --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/web/servlet/springmvc/errorhandling/errorpageswithoutspringmvc/SomeController.kt @@ -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 \ No newline at end of file diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle index d88b8402a48..0995887fabf 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/build.gradle @@ -54,7 +54,6 @@ dependencies { testImplementation("org.assertj:assertj-core") testImplementation("org.graalvm.buildtools:native-gradle-plugin") 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-daemon-client:$kotlinVersion") testImplementation("org.junit.jupiter:junit-jupiter") diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/KotlinPluginAction.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/KotlinPluginAction.java index afb5eefac11..30ce7061e2d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/KotlinPluginAction.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/KotlinPluginAction.java @@ -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 diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleMultiDslExtension.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleMultiDslExtension.java index 7683e044fec..67c9c7f066c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleMultiDslExtension.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/junit/GradleMultiDslExtension.java @@ -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 getAdditionalExtensions() { - GradleBuild gradleBuild = new PluginClasspathGradleBuild(this.dsl) - .gradleVersion(GradleVersions.minimumCompatible()); + GradleBuild gradleBuild = new PluginClasspathGradleBuild(this.dsl); return Arrays.asList(new GradleBuildFieldSetter(gradleBuild), new GradleBuildExtension()); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests.java index ebc3a9cc5b2..e2fd064074e 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests.java @@ -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() { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/PluginClasspathGradleBuild.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/PluginClasspathGradleBuild.java index 14d1700b433..f4c14f2d3d1 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/PluginClasspathGradleBuild.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/testkit/PluginClasspathGradleBuild.java @@ -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 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 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) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests-kotlinCompileTasksCanOverrideDefaultJavaParametersFlag.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests-kotlinCompileTasksCanOverrideDefaultJavaParametersFlag.gradle index 625f97ccd43..48bf87f1149 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests-kotlinCompileTasksCanOverrideDefaultJavaParametersFlag.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests-kotlinCompileTasksCanOverrideDefaultJavaParametersFlag.gradle @@ -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()}" } } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests-kotlinCompileTasksUseJavaParametersFlagByDefault.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests-kotlinCompileTasksUseJavaParametersFlagByDefault.gradle index f5be02c186b..1058b326845 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests-kotlinCompileTasksUseJavaParametersFlagByDefault.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/plugin/KotlinPluginActionIntegrationTests-kotlinCompileTasksUseJavaParametersFlagByDefault.gradle @@ -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()}" } } }