Kotlin 2.5 Upgrade: JDK 17, Breaking Changes, When to Move
Kotlin 2.5.0 is cheap in code and can be expensive in CI. The compiler now refuses to run on JDKs older than 17, and the unused return value checker is on by default. Here's who should move now, who should wait, what it costs, and a path that keeps every step small.
Download the code The Spring Boot 4.2 service on Kotlin 2.5.0 and 2.4.21, with 31 tests, the checker and Reactor cases, and the JDK 17 checks. kotlin-2-5-0-upgrade-notes.zip · 219 KBContents10 sections
Should You Upgrade Now?#
Kotlin 2.5.0 shipped on December 2, 2026. On a Spring Boot service built with Gradle 9, expect a cheap upgrade. In my Spring Boot 4.2 sample, the Spring app needed no code changes. What you’ll notice is new warnings from the unused return value checker, which is now on by default.
Two changes can stop a build. A build that runs the Kotlin compiler on a JDK older than 17 now fails. A build that turns warnings into errors may fail on the checker’s warnings. A few removals fail only if you use them; they’re listed below. You can fix all of it on 2.4.21, before you bump. Waiting for 2.5.20 won’t make that work smaller, because that’s when the JDK opt-out goes.
A quick skip test: if your build runs on Gradle 9, it already runs on JDK 17, because Gradle needs JVM 17 or later to run. Then the JDK section only matters for Maven jobs and scripts.
I ran 2.5.0 on a copy of my Spring Boot 4.2 sample service, plus tiny projects for the JDK cases, and compared the results with 2.4.21 where the comparison matters. I first ran the checks on 2.5.0-RC2, then again on the release: every compiler message came out the same. The Reactor cases came later, on 2.5.0 only. Every message quoted below is from the 2.5.0 runs.
Staying on 2.4 is fair for now: Spring Boot 4.2 manages Kotlin 2.4.21, so moving to 2.5 means overriding the version Boot picks for you. What you can’t skip forever is the JDK work.
Now, 2.5.20, or Stay on 2.4?#
Your build decides the move, not the release.
| Your build | Move | Why |
|---|---|---|
| Gradle 9, warnings stay warnings | Bump on 2.5.0, or on its first bug-fix release | Gradle 9.9.2 won’t build on JDK 8, so the compiler already runs on 17 or later |
Warnings as errors (allWarningsAsErrors) |
Count the checker’s warnings on 2.4.21, then bump | 2.4.21 in check mode gives a close count; in the sample, the warnings matched line for line |
| Maven, Gradle 8, or any CI agent running on JDK 8 to 16 | Move to JDK 17 on 2.4.21, then bump | The 2.5 compiler fails on older JDKs, and the opt-out ends with 2.5.20 |
A module pins languageVersion 2.0 or 2.1 |
Raise it first | 2.5 no longer supports either |
| Happy on Boot 4.2, no need for anything new | Stay on 2.4.21, but plan the JDK work | 2.4 has stdlib security support until December 3, 2027 |
“Stay on 2.4” means 2.4.21: security fixes ship only for the latest release in a line.
Should you wait? 2.5.20, planned for March 2027, is a tooling release with bug fixes. A bug-fix release for 2.5.0 usually comes sooner: last time, 2.4.10 came about six weeks after 2.4.0. None is scheduled yet. The RC still fixed an inference regression (KT-91112), so a big codebase can reasonably wait for that first bug-fix release.
What waiting doesn’t buy is a smaller JDK move. The release notes say the opt-out “will be removed in Kotlin 2.5.20 when JDK 17 becomes mandatory.” My lean: do the JDK and warnings work now, on 2.4.21. Then the bump is a one-line PR.
The JDK 17 Floor: Who It Hits#
This is the change that can cost real time. It’s about the JDK that runs the compiler, not the bytecode you produce or the JDK you run in production.
Kotlin 2.5.0 “introduces a compilation error as the next step toward raising the minimum JDK version required to run the Kotlin compiler from JDK 8 to JDK 17.” Beta1 made it a warning (KT-89211), and Beta2 an error (KT-88174). Here’s Gradle 8.14.3 on JDK 8 with 2.5.0:
e: Running Kotlin compiler using JDK 8 will not be supported in future versions of Kotlin. Consider upgrading to at least JDK 17 or supplying '-Xallow-pre-17-runtime-jdk' (which will only work until Kotlin 2.5.20-Beta1). See https://jb.gg/kotlin-compiler-jdk-17-migration for more details.It reads like a warning, but the build fails. Note the date, too: the opt-out works “until Kotlin 2.5.20-Beta1”. So it stops working in the first 2.5.20 preview, before 2.5.20 itself, if you try previews.
Who it hits, from the sample:
- Gradle 9: not you. In Gradle, “the Kotlin compiler always runs on the JDK the Gradle daemon is running on”, and Gradle itself needs JVM 17 or later. Gradle 9.9.2 on JDK 8 stops first:
Gradle requires JVM 17 or later to run. Your build is currently configured to use JVM 8.One trap: the wrapper itself runs on JVM 8, so./gradlew --versionstill works there. Check with a real task. - Gradle 8 on an old JDK: the error above. 2.4.21 builds the same project.
- Maven on JDK 8: the same message, as
[ERROR]. The compiler ran on the JDK Maven itself ran on, soJAVA_HOMEdecides. - Maven Toolchains don’t help. Since 2.4.0, the Kotlin Maven plugin picks up a toolchain. With one selecting JDK 17, Maven logged
Selected JDK toolchain, then failed with the same error. What counted was the JDK Maven itself ran on. The compatibility guide confirms it:jdkToolchainandmaven-toolchains-plugin“don’t change the runtime JDK used by the Maven process.”
Spring Boot 4 already needs Java 17, so a Boot 4 app’s runtime is fine. The risk is CI agent images, Maven jobs, Docker build stages, and scripts that call kotlinc. Move each to 17 on 2.4.21, in its own PR, so a red build tells you it was the JDK.
For an agent you can’t move this month, the opt-out works. On Maven:
<configuration>
<args>
<arg>-Xallow-pre-17-runtime-jdk</arg>
</args>
</configuration>On Gradle 8:
kotlin.compilerOptions.freeCompilerArgs.add("-Xallow-pre-17-runtime-jdk")It passed silently on Maven and Gradle, with no hint that it’s temporary. Give it a ticket with a date.
Does Kotlin 2.5 still support Java 8?#
Yes, as a target. In the sample, Gradle 9.9.2 on JDK 17 built a module with this on 2.5.0:
kotlin {
jvmToolchain(8)
}Its classes are major version: 52, and on JDK 8 they print Kotlin 2.5.0 on Java 1.8.0_372. Maven on JDK 17 with jvmTarget 1.8 did the same. The reverse holds too: jvmToolchain() sets the JDK you compile against, not the one the Gradle daemon runs on. The floor moves build machines, not production.
The Unused Return Value Checker Is On#
This is the change everyone will see. It reports a result you compute and then drop. It costs time only where warnings fail the build.
The checker is stable in 2.5 and “now enabled by default in check mode”. That mode reports dropped results only from marked functions, “including most functions in the Kotlin standard library”, and from Java code marked with an annotation it recognizes, such as Spring’s or Error Prone’s @CheckReturnValue.
Some of what the default build caught (paths shortened here and below; real logs show file:// and the full path):
fun tagArticle(article: Article): Article {
val tags = article.tags
tags + "kotlin" // a new list, dropped: `tags` is unchanged
return article
}
fun sameTags(actual: List<String>, expected: List<String>) {
actual == expected // a comparison as a statement (KT-2264)
}
fun fetchQuote(client: RestClient) {
client.get().uri("/quotes/1").retrieve() // Spring's @CheckReturnValue retrieve(), dropped
}w: src/main/kotlin/notes/IgnoredResults.kt:18:10 Unused return value of 'plus'.
w: src/main/kotlin/notes/IgnoredResults.kt:46:12 Unused return value.
w: src/main/kotlin/notes/IgnoredResults.kt:50:35 Unused return value of 'retrieve'.The first is a real bug: a test in the sample proves tags doesn’t change. The third is the Spring finding. Spring Framework 7.1.0 marks RestClient’s retrieve() with @CheckReturnValue, and the checker honors Spring’s annotation. So a dropped retrieve() warns by default. The other marked Spring methods I found are 16 AssertJ helpers in spring-boot-test.
check doesn’t report a dropped copy() on your own data class, or a dropped call to your own unannotated function. Those need full, which treats every function in your project as marked:
w: src/main/kotlin/notes/IgnoredResults.kt:36:13 Unused return value of 'copy'.
w: src/main/kotlin/notes/IgnoredResults.kt:41:5 Unused return value of 'slugOf'.MutableList.add never warned, even in full. On the Spring app’s own code, check found nothing, and full found one dropped call in a test. That proves nothing about your code, so count your own.
Does it catch a Mono nobody subscribes to?#
No, not by default. In Reactor, a Mono or Flux that nothing subscribes to never runs, so dropping one drops the work. It’s the bug you’d most want this checker to catch in a Reactor codebase. I planted four cases:
fun auditWithFactory(log: AuditLog, entry: String) {
Mono.fromRunnable<Void> { log.entries += entry } // Reactor's own factory, never subscribed
}
fun auditWithOwnFunction(log: AuditLog, entry: String) {
log.record(entry) // our own function's Mono, never subscribed
}
fun auditEach(log: AuditLog, entries: List<String>) {
Flux.fromIterable(entries).doOnNext { log.entries += it } // a Flux, never subscribed
}
fun auditAndForget(log: AuditLog, entry: String) {
log.record(entry).subscribe() // subscribed: the Disposable is dropped, which is fine
}The sample’s tests show the first three never write to the log, while the same constructions, subscribed, do. In the default check mode, 2.5.0 printed no warnings for any of them: Reactor 3.9 marks none of its methods, so the checker has nothing to go on. In full mode, it caught only the second, where the Mono comes from a function of our own:
w: src/main/kotlin/notes/IgnoredMonos.kt:23:9 Unused return value of 'record'.The good news is the last case: a dropped Disposable from subscribe() never warned, so fire-and-forget code isn’t noise. If your code returns Mono and Flux from its own services, full mode catches the drops at your own boundaries, and @MustUseReturnValues on those classes should too. Reactor’s own operators stay unchecked, so a chain that’s built and never returned, like a delayUntil wait, still needs a reviewer.
Count on 2.4.21. With -Xreturn-value-checker=check, 2.4.21 printed the same five checker warnings as 2.5.0’s default, line for line. That’s your budget, measured before you bump. It may run slightly high: 2.5 marks a few more standard library functions as safe to ignore, such as thread {} and some Timer.schedule overloads. With allWarningsAsErrors, each becomes an error under e: warnings found and -Werror specified. If you count by grepping CI logs for w:, note that Gradle 9.9.2 with --warning-mode all prints them as Problem found blocks instead.
Each warning is a bug to fix, a drop to make explicit with val _ = …, or a function to mark @IgnorableReturnValue. On 2.4.21, val _ = and @IgnorableReturnValue only compile once the checker is on, so turn it on first.
How do I turn off the unused return value checker?#
Pass -Xreturn-value-checker=disable. In the sample, it silenced every checker warning. KGP 2.5 also adds a Gradle DSL (KT-74808), on the kotlin extension rather than in compilerOptions. It’s experimental, so it needs an opt-in, or Gradle warns that it’s an experimental API:
@OptIn(ExperimentalKotlinGradlePluginApi::class)
kotlin {
returnValueCheckerMode = ReturnValueCheckerMode.Disabled
}The enum has Disabled, Check and Full; the sample compiled the setting with Full. A second property, returnValueCheckerModeForTests, sets the mode for source sets other than main, and defaults to the main setting. So you can adopt full in production code without failing on every dropped result in your tests. With languageVersion 2.4, 2.5.0 printed no checker warnings either. I’d fix the warnings rather than hide them, though. In check mode, each one is a result its author marked as not to be dropped.
Type Inference Changed Underneath You#
Kotlin 2.5 generates fewer constraints during type inference, to stop hangs on complex generic code. In edge cases, the compiler “might infer different types, select different overloads, or report different diagnostics.” @BuilderInference is deprecated too (KT-52400).
Your test suite is the check. If something breaks only on 2.5, try -XXLanguage:-EliminateSecondKindIncorporation once to confirm the cause, then fix the code and drop the flag. The compiler warns that “This build uses unsafe internal compiler arguments”.
Removed and Deprecated: What to Grep For#
languageVersion2.0 or 2.1 (KT-86132):e: Language version 2.1 is no longer supported; use version 2.2 or greater instead.2.2 builds, with a deprecation warning (KT-86131), so expect it to go next. The sample setapiVersionto the same value.-Xcontext-receivers(KT-87826): a leftover from before 2.4, where 2.4.21 already fails on it. 2.5.0 only warns:The argument '-Xcontext-receivers' was removed in Kotlin 2.5.0. It has no effect.Use context parameters.- K1 compiler flags are deprecated (KT-75990).
- Gradle versions. KGP 2.5.0 is “fully compatible with Gradle 8.14 through 9.8.1”. Newer Gradle works, with possible deprecation warnings; the sample ran on 9.9.2 without any. On Gradle 8.14.3, KGP 2.4.21 warns that
The minimum supported Gradle version will become Gradle 8.14.4 in Kotlin 2.5.0., but KGP 2.5.0 printed no such warning on 8.14.3. Move to the latest 8.14.x anyway. “Kotlin Gradle plugin was loaded multiple times” is now an error (KT-61225), and thekotlin.compiler.runViaBuildToolsApiproperty no longer does anything (KT-85434). I didn’t test those two. - Smart casts after
==with Java values (KTLC-410). Aftera == b(or===), wherebis a Java platform type or a type parameter with a nullable bound, the compiler used to smart castato non-null. That was unsound, so code that relied on it no longer compiles. The fix is an explicit null check, or@NotNullon the Java side. I didn’t hit it in the sample, but a codebase that mixes Java and Kotlin might. - Range equality (KTLC-421):
1..2 == 1..2 step 1is nowtrueboth ways round, and thehashCode()of ranges changes. Mostly that matters to a set or map holding both ranges and progressions, or to code that stores a range’shashCode(). add()on a Java@Unmodifiable Listis now an error,Unresolved reference 'add' on receiver of type 'List<String!>'., where 2.4.21 warned, as my 2.3.20 notes predicted.- Lombok on Kotlin classes: not a break, but if you still use Lombok, the compiler plugin now supports several Lombok annotations on one Kotlin class, and
lombok.fieldDefaults.defaultPrivate. I didn’t test either.
The Path#
Each step is its own PR. The first three land on 2.4.21.
1. Move every compiler to JDK 17. CI images, Maven JAVA_HOME, Docker build stages, scripts. On Gradle 9 with no scripts calling kotlinc, skip it. Ships when: CI is green with nothing older than 17 running Kotlin.
2. Clear the removals. No languageVersion below 2.3, Gradle on the latest 8.14.x or 9.x, no add() on Java unmodifiable lists, and warnings at zero, as in my 2.4 notes. Ships when: each grep comes back empty.
3. Measure the checker. Turn on check on a branch, or with allWarningsAsErrors off, then count and decide each warning. Commit the flag only once the warnings are fixed or marked. After the bump, check is the default, so the flag can go. Ships when: zero checker warnings, or a counted list nobody fails the build on.
4. Bump to 2.5.0. The sample imports Boot 4.2’s BOM as a Gradle platform(), and it needed no fix: conflict resolution lifted kotlin-stdlib and kotlin-reflect to 2.5.0. I didn’t test the io.spring.dependency-management plugin, so if you use it, check what resolves with dependencyInsight. On Maven with spring-boot-starter-parent, setting <kotlin.version> moved them and the plugin. Ships when: the build is clean and the tests pass. The sample’s 19 Spring tests passed on both versions.
5. Watch staging. Rolling back is reverting one PR.
How You Know You’re Done#
- Nothing runs the Kotlin compiler on a JDK older than 17, and
-Xallow-pre-17-runtime-jdkappears nowhere, or has a dated ticket. - Zero checker warnings, or every remaining one is a counted decision.
- No
languageVersionbelow 2.3, no-Xcontext-receivers, no-XXLanguage:-EliminateSecondKindIncorporation. - Gradle on the latest 8.14.x, or on 9.x.
- No code drops a
MonoorFlux.checkwon’t tell you;fullor@MustUseReturnValuescatches it only in your own functions. -
kotlin-stdlibandkotlin-reflectresolve to the same 2.5 version.
Everything Else#
Name-based destructuring is stable in only-syntax mode, now the default. The old syntax keeps binding by position, so the 2.3.20 notes’ swapped-names bug still compiles on 2.5.0. The new syntax binds by name, with no flag:
fun namedInAnyOrder(user: User): Pair<String, String> {
(val email, val username) = user
return email to username
}To find old code with crossed names, run -Xname-based-destructuring=name-mismatch once. It works on 2.4.21 too:
w: src/main/kotlin/notes/Destructuring.kt:8:10 Variable name 'email' differs from accessed property name 'username'. This syntax will be used for name-based destructuring in a future release, and this code will change its meaning.It also flags a Pair destructured into other names, so expect noise. More on data classes.
Uuid.generateV4() and generateV7() are stable (KT-89662); 2.4.21 still needs opt-in. Full value classes (several properties, no identity) and companion blocks are experimental: nice to try, not a reason to upgrade. Cross-module inlining is on by default, but only for klib compilation, so JVM builds aren’t affected.
Conclusion#
Kotlin 2.5.0 is a build-machine release dressed as a language release. The time goes on the JDK floor and the checker’s warnings, and you can do both on 2.4.21, now, whichever version you pick. Then the upgrade is one PR. Refill the red mug before you open the CI agent list: that’s where this one is decided.
The checks I ran, and every compiler message quoted here, are in the sample: download it as a zip.
Sources
- What’s new in Kotlin 2.5.0
- Kotlin 2.5.0 changelog, with the RC2, RC, Beta2 and Beta1 changelogs
- Compatibility guide for Kotlin 2.5.x
- Unused return value checker
- Destructuring declarations
- Kotlin release process
- Configure a Gradle project
- Gradle compatibility matrix
- What’s new in Kotlin 2.4.0
- Kotlin compiler JDK 17 migration
- The complete code for this post (zip)
