1

I would like to come up with some empirical evidence for, or against, migrating spring boot 2.7.x to kotlin >= 1.7.x.

Looking at the spring boot documentation, kotlin version 1.6.21 is listed. However, in some of the spring examples listed, point to at least kotlin 1.7.X less than one month after release.

Gradle has a pretty good compatibility matrix for kotlin usage, of which doesn't even list the current version that comes standard on the spring Initializer start.spring.io

Kotlin Version Gradle min and max versions
1.8.20 6.8.3 – 7.6.0
1.8.0 6.8.3 – 7.3.3
1.7.20 6.7.1 – 7.1.1
Jolley71717
  • 678
  • 1
  • 8
  • 20
  • I don', Spring Boot is a framework whereas Kotlin is a programming language as well as Java. Maybe you are making a scratch project with Kotlin language and Gradle. – Louis May 09 '23 at 23:59
  • Spring Boot is a framework, but it has recommended language versions. The Spring Boot team should have compatibility documentation somewhere describing why their Spring Initilizr recommends kotlin 1.6.21 for Spring Boot 2.7.11 rather than a newer version of kotlin. – Jolley71717 May 10 '23 at 00:09
  • I didn't get your point exactly, Spring Boot is a framework whereas Kotlin is a programming language as well as Java. Maybe you are making a scratch project with Kotlin language and Gradle. As give you the answer, any version of Spring Boot supports Kotlin. Kotlin can run on JVM and is fully interactive with Java. https://docs.gradle.org/ https://maven.apache.org/ You can refer these sites to know how to import Kotlin into Spring Boot project. – Louis May 10 '23 at 00:10
  • Nope. Spring Boot supports Kotlin 1.3+. https://docs.spring.io/spring-framework/docs/current/reference/html/languages.html#kotlin Actually, they are independent, and all you need to do for using Kotlin is Kotlin Standard Libraries for JVM. You might agree that Spring Boot uses Java, and as well as Kotlin code is converted to JVM binary code. – Louis May 10 '23 at 00:19
  • 3
    Not clear exactly what the question is. Are you asking about what criteria to use when selecting the Kotlin version you are compiling with, or are you asking what criteria Spring’s developers used to determine what version of Kotlin to compile their Kotlin extension libraries with? – Tenfour04 May 10 '23 at 00:20
  • The issue is not how to import kotlin, more why not to upgrade the kotlin you are using in your Spring Boot project. While it's true that Spring Boot does work with any maximum version of kotlin, it's important to find the "recommended" versions so that you are working with frameworks and language versions that have been tested together and are in a configuration that is recommended by both Spring and JetBrains. (Rhetorical question) If all versions are supported, why doesn't Spring just update their kotlin jvm plugin to `1.8.x`? – Jolley71717 May 10 '23 at 00:22
  • 1
    @xuxianjin OP seems to be asking about Kotlin version compatibility with versions of Spring Boot. Unlike Java, Kotlin does not maintain backwards compatibility with older versions of Kotlin, so it is possible to choose a Kotlin version that will cause a standard library version conflict with dependencies that were compiled with a different version of Kotlin. – Tenfour04 May 10 '23 at 00:23
  • @Tenfour04, that's a good distinction to make. It's a little of both. I'm trying to come up with criteria for upgrading the kotlin version my own projects are using while staying close to the intent the Spring developers seem to have maintained – Jolley71717 May 10 '23 at 00:25
  • I’m not a Spring user, but I can say that if Spring claims it can work with any version of Kotlin up to the latest, then for that claim to be true, they must not be using any standard library functions that have been deprecated for more than two Kotlin versions, thereby being now removed from the standard library or even having their behavior changed. Kotlin occasionally deprecates a standard library function, then two or three versions later, the function is entirely removed. And in some cases they bring back the deprecated function later with different behavior. See `Iterable.min` – Tenfour04 May 10 '23 at 00:27
  • This sounds like a question to the [Spring Boot](https://github.com/spring-projects/spring-boot/issues) project itself? – Jorge Campos May 10 '23 at 00:37

1 Answers1

3

Spring Boot 2.7.x uses Kotlin 1.6.x because Kotlin 1.6 was the latest version that was available when Spring Boot 2.7 was released. It hasn't been upgraded to Kotlin 1.7 or 1.8 as the policy for managing dependencies prohibits doing so:

Spring Boot provides managed dependencies for many third-party libraries. These libraries are upgraded only at the patch level for any given Spring Boot patch release. Minor and major version upgrades of third-party libraries are only applied in Spring Boot minor or major releases. You should check the EOL policies of projects that you depend on since you may find that you’re using a supported version of Spring Boot against an unsupported third-party library.

As noted in the comments, you can use Kotlin 1.3.x or later with Spring Boot 2.7.x. The Kotlin baseline was raised in Spring Boot 3.0 and it requires 1.7.x or later.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242