Skip to content

Commit

Permalink
Upgrade to Kotlin 2.1.10
Browse files Browse the repository at this point in the history
- Upgrade kotlinVersion to 2.1.10
- Remove org.jetbrains.kotlin:kotlin-compiler-embeddable from dependencies
- Replace deprecated kotlinOptions with compilerOptions
- Update KotlinConventions of ConventionsPlugin to set Kotlin apiVersion
  and languageVersion to 2.1
- Move spring-boot-doc Kotlin examples to kotlin subpackage to prevent
  Redeclaration compile error
- Upgrade PluginClasspathGradleBuild to inject missed Kotlin compiler
  related jars

See gh-38539

Signed-off-by: Dmitry Sulman <[email protected]>
  • Loading branch information
dmitrysulman committed Feb 28, 2025
1 parent 7b9da78 commit 1d9bbc4
Show file tree
Hide file tree
Showing 366 changed files with 438 additions and 400 deletions.
1 change: 0 additions & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ dependencies {
implementation("org.apache.maven:maven-embedder:${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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -35,6 +35,9 @@
* When the {@link AntoraPlugin} is applied, the conventions in {@link AntoraConventions}
* are applied.
*
* When the {@code org.jetbrains.kotlin.jvm} plugin is applied, the conventions in
* {@link KotlinConventions} are applied.
*
* @author Andy Wilkinson
* @author Christoph Dreis
* @author Mike Smithson
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -25,7 +25,9 @@
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;

/**
Expand All @@ -35,7 +37,7 @@
* <ul>
* <li>{@link KotlinCompile} tasks are configured to:
* <ul>
* <li>Use {@code apiVersion} and {@code languageVersion} 1.7.
* <li>Use {@code apiVersion} and {@code languageVersion} 2.1.
* <li>Use {@code jvmTarget} 17.
* <li>Treat all warnings as errors
* <li>Suppress version warnings
Expand All @@ -56,14 +58,14 @@ void apply(Project project) {
}

private void configure(KotlinCompile compile) {
KotlinJvmOptions kotlinOptions = compile.getKotlinOptions();
kotlinOptions.setApiVersion("1.7");
kotlinOptions.setLanguageVersion("1.7");
kotlinOptions.setJvmTarget("17");
kotlinOptions.setAllWarningsAsErrors(true);
List<String> freeCompilerArgs = new ArrayList<>(kotlinOptions.getFreeCompilerArgs());
KotlinJvmCompilerOptions kotlinOptions = compile.getCompilerOptions();
kotlinOptions.getApiVersion().set(KotlinVersion.KOTLIN_2_1);
kotlinOptions.getLanguageVersion().set(KotlinVersion.KOTLIN_2_1);
kotlinOptions.getJvmTarget().set(JvmTarget.JVM_17);
kotlinOptions.getAllWarningsAsErrors().set(true);
List<String> freeCompilerArgs = new ArrayList<>(kotlinOptions.getFreeCompilerArgs().get());
freeCompilerArgs.add("-Xsuppress-version-warnings");
kotlinOptions.setFreeCompilerArgs(freeCompilerArgs);
kotlinOptions.getFreeCompilerArgs().set(freeCompilerArgs);
}

private void configureDokkatoo(Project project) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# === INCLUDE-CODE LOCATIONS ===

include-java=ROOT:example$java/org/springframework/boot/docs
include-kotlin= ROOT:example$kotlin/org/springframework/boot/docs
include-kotlin= ROOT:example$kotlin/org/springframework/boot/docs/kotlin

# === URLs ===

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ hamcrestVersion=3.0
jacksonVersion=2.18.2
javaFormatVersion=0.0.43
junitJupiterVersion=5.11.4
kotlinVersion=1.9.25
kotlinVersion=2.1.10
mavenVersion=3.9.4
mockitoVersion=5.15.2
nativeBuildToolsVersion=0.10.5
Expand Down
5 changes: 3 additions & 2 deletions spring-boot-project/spring-boot-dependencies/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -1193,8 +1193,9 @@ bom {
}
library("Kotlin", "${kotlinVersion}") {
prohibit {
versionRange "[2.0.0-Beta1,)"
because "it exceeds our baseline"
contains "-Beta"
contains "-RC"
because "we don't want betas or release candidates"
}
group("org.jetbrains.kotlin") {
imports = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

package org.springframework.boot.docs.data.nosql.cassandra.connecting;

class User {
public class User {

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package org.springframework.boot.docs.features.externalconfig.typesafeconfigurationproperties.usingannotatedtypes;

class Server {
public class Server {

Server(Object remoteAddress) {
public Server(Object remoteAddress) {
}

void start() {
public void start() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

package org.springframework.boot.docs.features.springapplication.applicationavailability.managing;

class CacheCompletelyBrokenException extends RuntimeException {
public class CacheCompletelyBrokenException extends RuntimeException {

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package org.springframework.boot.docs.web.servlet.springmvc.errorhandling;

class MyErrorBody {
public class MyErrorBody {

MyErrorBody(int value, String message) {
public MyErrorBody(int value, String message) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

package org.springframework.boot.docs.web.servlet.springmvc.errorhandling;

class MyException extends RuntimeException {
public class MyException extends RuntimeException {

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

package org.springframework.boot.docs.web.servlet.springmvc.errorhandling;

class SomeController {
public class SomeController {

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.cloudfoundry.customcontextpath
package org.springframework.boot.docs.kotlin.actuator.cloudfoundry.customcontextpath

import jakarta.servlet.GenericServlet
import jakarta.servlet.Servlet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.actuator.cloudfoundry.customcontextpath
package org.springframework.boot.docs.kotlin.actuator.cloudfoundry.customcontextpath

import org.springframework.boot.autoconfigure.web.reactive.WebFluxProperties
import org.springframework.boot.context.properties.EnableConfigurationProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.endpoints.health.reactivehealthindicators
package org.springframework.boot.docs.kotlin.actuator.endpoints.health.reactivehealthindicators

import org.springframework.boot.actuate.health.Health
import org.springframework.boot.actuate.health.ReactiveHealthIndicator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.endpoints.health.writingcustomhealthindicators
package org.springframework.boot.docs.kotlin.actuator.endpoints.health.writingcustomhealthindicators

import org.springframework.boot.actuate.health.Health
import org.springframework.boot.actuate.health.HealthIndicator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.endpoints.implementingcustom
package org.springframework.boot.docs.kotlin.actuator.endpoints.implementingcustom

class CustomData(val name: String, val counter: Int)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.endpoints.implementingcustom
package org.springframework.boot.docs.kotlin.actuator.endpoints.implementingcustom

import org.springframework.boot.actuate.endpoint.annotation.Endpoint
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.endpoints.info.writingcustominfocontributors
package org.springframework.boot.docs.kotlin.actuator.endpoints.info.writingcustominfocontributors

import org.springframework.boot.actuate.info.Info
import org.springframework.boot.actuate.info.InfoContributor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.endpoints.security.exposeall
package org.springframework.boot.docs.kotlin.actuator.endpoints.security.exposeall

import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest
import org.springframework.context.annotation.Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.endpoints.security.typical
package org.springframework.boot.docs.kotlin.actuator.endpoints.security.typical

import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest
import org.springframework.context.annotation.Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.metrics.customizing
package org.springframework.boot.docs.kotlin.actuator.metrics.customizing

import io.micrometer.core.instrument.config.MeterFilter
import org.springframework.context.annotation.Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.metrics.export.graphite
package org.springframework.boot.docs.kotlin.actuator.metrics.export.graphite

import io.micrometer.core.instrument.Clock
import io.micrometer.core.instrument.Meter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.metrics.export.jmx
package org.springframework.boot.docs.kotlin.actuator.metrics.export.jmx

import io.micrometer.core.instrument.Clock
import io.micrometer.core.instrument.Meter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.metrics.gettingstarted.commontags
package org.springframework.boot.docs.kotlin.actuator.metrics.gettingstarted.commontags

import io.micrometer.core.instrument.MeterRegistry
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.metrics.gettingstarted.specifictype
package org.springframework.boot.docs.kotlin.actuator.metrics.gettingstarted.specifictype

import io.micrometer.core.instrument.Meter
import io.micrometer.core.instrument.config.NamingConvention
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.metrics.registeringcustom
package org.springframework.boot.docs.kotlin.actuator.metrics.registeringcustom

internal class Dictionary {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.metrics.registeringcustom
package org.springframework.boot.docs.kotlin.actuator.metrics.registeringcustom

import io.micrometer.core.instrument.MeterRegistry
import io.micrometer.core.instrument.Tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.metrics.registeringcustom
package org.springframework.boot.docs.kotlin.actuator.metrics.registeringcustom

import io.micrometer.core.instrument.Gauge
import io.micrometer.core.instrument.binder.MeterBinder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.metrics.registeringcustom
package org.springframework.boot.docs.kotlin.actuator.metrics.registeringcustom

class Queue {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.metrics.supported.mongodb.command
package org.springframework.boot.docs.kotlin.actuator.metrics.supported.mongodb.command

import com.mongodb.event.CommandEvent
import io.micrometer.core.instrument.Tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.metrics.supported.mongodb.command
package org.springframework.boot.docs.kotlin.actuator.metrics.supported.mongodb.command

import io.micrometer.core.instrument.binder.mongodb.MongoCommandTagsProvider
import org.springframework.context.annotation.Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.metrics.supported.mongodb.connectionpool
package org.springframework.boot.docs.kotlin.actuator.metrics.supported.mongodb.connectionpool

import com.mongodb.event.ConnectionPoolCreatedEvent
import io.micrometer.core.instrument.Tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.actuator.metrics.supported.mongodb.connectionpool
package org.springframework.boot.docs.kotlin.actuator.metrics.supported.mongodb.connectionpool

import io.micrometer.core.instrument.binder.mongodb.MongoConnectionPoolTagsProvider
import org.springframework.context.annotation.Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.buildtoolplugins.otherbuildsystems.examplerepackageimplementation
package org.springframework.boot.docs.kotlin.buildtoolplugins.otherbuildsystems.examplerepackageimplementation

import org.springframework.boot.loader.tools.Library
import org.springframework.boot.loader.tools.LibraryCallback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.configurationmetadata.annotationprocessor.automaticmetadatageneration
package org.springframework.boot.docs.kotlin.configurationmetadata.annotationprocessor.automaticmetadatageneration

import org.springframework.boot.context.properties.ConfigurationProperties
import java.util.Arrays
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.configurationmetadata.annotationprocessor.automaticmetadatageneration
package org.springframework.boot.docs.kotlin.configurationmetadata.annotationprocessor.automaticmetadatageneration

import org.springframework.boot.context.properties.ConfigurationProperties

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.springframework.boot.docs.configurationmetadata.annotationprocessor.automaticmetadatageneration.nestedproperties
package org.springframework.boot.docs.kotlin.configurationmetadata.annotationprocessor.automaticmetadatageneration.nestedproperties

import org.springframework.boot.context.properties.ConfigurationProperties

Expand Down
Loading

0 comments on commit 1d9bbc4

Please sign in to comment.