Upgrade to Kotlin 1.4 M2

- The compiler is configured to retain compatibility with Kotlin 1.3.
- Explicit API mode is not yet enabled but could be in the future.
- A workaround for Gradle build is required for now, see
  https://youtrack.jetbrains.com/issue/KT-39610 for more details.
- Some exceptions thrown by Kotlin have changed to NullPointerException,
  see https://youtrack.jetbrains.com/issue/KT-22275 for more details.

Closes gh-24171
This commit is contained in:
Sébastien Deleuze 2020-06-16 15:07:13 +02:00
parent 97aba77cc1
commit 2a74eff10f
9 changed files with 45 additions and 11 deletions

View File

@ -1,6 +1,6 @@
plugins {
id 'io.spring.dependency-management' version '1.0.9.RELEASE' apply false
id 'org.jetbrains.kotlin.jvm' version '1.3.72' apply false
id 'org.jetbrains.kotlin.jvm' version '1.4-M2' apply false
id 'org.jetbrains.dokka' version '0.10.1' apply false
id 'org.asciidoctor.jvm.convert' version '2.4.0'
id 'io.spring.nohttp' version '0.0.4.RELEASE'
@ -28,8 +28,8 @@ configure(allprojects) { project ->
mavenBom "io.projectreactor:reactor-bom:2020.0.0-SNAPSHOT"
mavenBom "io.rsocket:rsocket-bom:1.0.1"
mavenBom "org.eclipse.jetty:jetty-bom:9.4.29.v20200521"
mavenBom "org.jetbrains.kotlin:kotlin-bom:1.3.72"
mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.3.5"
mavenBom "org.jetbrains.kotlin:kotlin-bom:1.4-M2"
mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.3.7-1.4-M2"
mavenBom "org.junit:junit-bom:5.6.2"
}
dependencies {
@ -285,6 +285,8 @@ configure(allprojects) { project ->
mavenCentral()
maven { url "https://repo.spring.io/libs-spring-framework-build" }
maven { url "https://repo.spring.io/snapshot" } // Reactor
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } // Kotlin
maven { url "https://kotlin.bintray.com/kotlinx" } // Coroutines
}
}
configurations.all {
@ -307,9 +309,16 @@ configure([rootProject] + javaProjects) { project ->
pluginManager.withPlugin("kotlin") {
apply plugin: "org.jetbrains.dokka"
// Workaround for https://youtrack.jetbrains.com/issue/KT-39610
configurations["kotlinCompilerPluginClasspath"].attributes.attribute(
org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE,
objects.named(Usage.class, "java-runtime")
)
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
languageVersion = "1.3"
apiVersion = "1.3"
freeCompilerArgs = ["-Xjsr305=strict"]
allWarningsAsErrors = true
}

View File

@ -2,6 +2,7 @@ pluginManagement {
repositories {
gradlePluginPortal()
maven { url 'https://repo.spring.io/plugins-release' }
maven { url "https://dl.bintray.com/kotlin/kotlin-eap" } // Kotlin
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors
* Copyright 2002-2020 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.
@ -53,7 +53,7 @@ class JdbcOperationsExtensionsTests {
@Test // gh-22682
fun `queryForObject with nullable RowMapper-like function`() {
every { template.queryForObject(sql, any<RowMapper<Int>>(), 3) } returns null
assertThat(template.queryForObject(sql, 3) { _, _ -> null as Int? }).isNull()
assertThat(template.queryForObject<Int?>(sql, 3) { _, _ -> null }).isNull()
verify { template.queryForObject(eq(sql), any<RowMapper<Int?>>(), eq(3)) }
}
@ -130,7 +130,7 @@ class JdbcOperationsExtensionsTests {
@Test
fun `query with RowMapper-like function`() {
val list = listOf(1, 2, 3)
val list = mutableListOf(1, 2, 3)
every { template.query(sql, ofType<RowMapper<*>>(), 3) } returns list
assertThat(template.query(sql, 3) { rs, _ ->
rs.getInt(1)

View File

@ -2,6 +2,12 @@ description = "Spring Messaging"
apply plugin: "kotlin"
// Workaround for https://youtrack.jetbrains.com/issue/KT-39610
configurations["optional"].attributes.attribute(
org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE,
objects.named(Usage.class, "java-runtime")
)
dependencies {
compile(project(":spring-beans"))
compile(project(":spring-core"))

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -132,7 +132,7 @@ class SimpAnnotationMethodMessageHandlerKotlinTests {
messageHandler.registerHandler(testController)
messageHandler.handleMessage(message)
assertThat(testController.exception).isNotNull()
assertThat(testController.exception).isInstanceOf(IllegalArgumentException::class.java)
assertThat(testController.exception).isInstanceOf(NullPointerException::class.java)
}
private fun createMessage(destination: String, headers: Map<String, String?>): Message<ByteArray> {

View File

@ -2,6 +2,12 @@ description = "Spring TestContext Framework"
apply plugin: "kotlin"
// Workaround for https://youtrack.jetbrains.com/issue/KT-39610
configurations["optional"].attributes.attribute(
org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE,
objects.named(Usage.class, "java-runtime")
)
dependencies {
compile(project(":spring-core"))
optional(project(":spring-aop"))

View File

@ -2,6 +2,12 @@ description = "Spring Transaction"
apply plugin: "kotlin"
// Workaround for https://youtrack.jetbrains.com/issue/KT-39610
configurations["optional"].attributes.attribute(
org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE,
objects.named(Usage.class, "java-runtime")
)
dependencies {
compile(project(":spring-beans"))
compile(project(":spring-core"))

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -139,7 +139,7 @@ class RequestParamMethodArgumentResolverKotlinTests {
@Test
fun resolveNonNullableNotRequiredWithoutParameter() {
assertThatExceptionOfType(TypeCastException::class.java).isThrownBy {
assertThatExceptionOfType(NullPointerException::class.java).isThrownBy {
resolver.resolveArgument(nonNullableParamNotRequired, null, webRequest, binderFactory) as String
}
}
@ -221,7 +221,7 @@ class RequestParamMethodArgumentResolverKotlinTests {
request.method = HttpMethod.POST.name
request.contentType = MediaType.MULTIPART_FORM_DATA_VALUE
assertThatExceptionOfType(TypeCastException::class.java).isThrownBy {
assertThatExceptionOfType(NullPointerException::class.java).isThrownBy {
resolver.resolveArgument(nonNullableMultipartParamNotRequired, null, webRequest, binderFactory) as MultipartFile
}
}

View File

@ -2,6 +2,12 @@ description = "Spring WebFlux"
apply plugin: "kotlin"
// Workaround for https://youtrack.jetbrains.com/issue/KT-39610
configurations["optional"].attributes.attribute(
org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE,
objects.named(Usage.class, "java-runtime")
)
dependencies {
compile(project(":spring-beans"))
compile(project(":spring-core"))