Skip to content

Align Kotlin jvmTarget with the Java version during UpgradeJavaVersion#1120

Draft
MBoegers wants to merge 1 commit into
mainfrom
upgrade-kotlin-jvmtarget
Draft

Align Kotlin jvmTarget with the Java version during UpgradeJavaVersion#1120
MBoegers wants to merge 1 commit into
mainfrom
upgrade-kotlin-jvmtarget

Conversation

@MBoegers
Copy link
Copy Markdown
Contributor

@MBoegers MBoegers commented May 29, 2026

Summary

  • Add UpgradeKotlinJvmTargetVersion and run it from UpgradeJavaVersion
  • Raise the Kotlin jvmTarget to match the requested Java version (Maven + Gradle)
  • Never downgrade; no-op for non-Kotlin projects

Problem

When UpgradeJavaVersion raises a project's Java version, the Kotlin compiler keeps emitting bytecode at the old jvmTarget, leaving Kotlin classes at a mismatched bytecode level.

Solution

A new UpgradeKotlinJvmTargetVersion(version) recipe, added to UpgradeJavaVersion's recipe list, raises the Kotlin jvmTarget to match across:

  • kotlin-maven-plugin <jvmTarget> configuration
  • Gradle Groovy and Kotlin DSL kotlinOptions/compilerOptions blocks (string and JvmTarget.JVM_X forms, including the jvmTarget.set(...) provider)

This flows automatically through the existing UpgradeBuildToJava*ForKotlin recipes. Adds rewrite-kotlin as an implementation dependency (needed to parse build.gradle.kts).

Test plan

  • New tests: Maven, Gradle Groovy, Gradle Kotlin DSL, do-not-downgrade, non-Kotlin no-ops, outside-block negatives

  • UpgradeJavaVersionTest regression passes

  • Full CI build (local full-suite run blocked by an unrelated Java-parser environment issue)

  • See moderneinc/customer-requests#2439

When UpgradeJavaVersion bumps a project's Java version, the Kotlin compiler
keeps emitting bytecode at the older jvmTarget, leaving Kotlin classes at a
mismatched bytecode level. UpgradeJavaVersion now also runs a new
UpgradeKotlinJvmTargetVersion recipe that raises the Kotlin jvmTarget to match
the requested Java version across:

- kotlin-maven-plugin <jvmTarget> configuration
- Gradle Groovy and Kotlin DSL kotlinOptions/compilerOptions blocks
  (string and JvmTarget.JVM_X forms, including the jvmTarget.set(...) provider)

It never downgrades, and is a no-op for non-Kotlin projects. This flows through
the existing UpgradeBuildToJava*ForKotlin recipes, which delegate to
UpgradeJavaVersion.

Discovered while testing the Spring Boot 4 migration for Kotlin.

See moderneinc/customer-requests#2439
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant