published fresh until

Kotlin: align compiler, plugins and CI JVM targets

Summary Pin a compatible Kotlin and Gradle pair, align Java/Kotlin artifact targets and provision the same JDK in CI. Preserve mismatch failures with kotlin.jvm.target.validation.mode=error

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run ./gradlew --version, pin the Kotlin JVM plugin and select jvmToolchain(17) only if Java 17 is the artifact's intended baseline.

Short answer

As of November 2026, Kotlin 2.4.21 with Gradle 9.7.0 is a concrete pair within the documented KGP compatibility matrix. Pin compiler plugins separately to their documented Kotlin compatibility. Toolchain JDK, Kotlin bytecode target, Java target and published runtime requirement must agree; the Kotlin compiler runs on the JDK running the Gradle daemon.

Choose / don't choose

  • Shared toolchain: choose for local/CI consistency; don't let whichever JDK launches Gradle silently decide artifact requirements (toolchains).
  • New compiler, older language/API: choose when consumers require that compatibility; don't assume lowering -api-version alone guarantees old compiler metadata compatibility (compiler options).
  • New language features: choose only after updating the consumer support contract; don't confuse standard-library API availability with bytecode level (compiler options).

Not for: Gradle build-logic upgrade steps; see gradle-8-to-9-8-2-upgrade-jdk-kotlin-dsl-configuration-cache.

Settings that matter

Setting or flagValue / defaultApplies toSource
id("org.jetbrains.kotlin.jvm") versionPin "2.4.21" for the pair above; keep compiler plugins compatibleKotlin releaseKGP matrix
compilerOptions.jvmTargetJvmTarget.fromTarget("17") for a Java 17 baseline; match Java target and consumer runtimeCurrent typed compiler DSLoptions
jvmToolchain17 for that same baseline; provision that JDK in CI or configure a compatible resolverCurrent KGP toolchain docs; JDK release linetoolchain
kotlin.jvm.target.validation.modeerror to reject mismatch; warning prints a message; ignore skips the check and produces no messagesCurrent KGP docsvalidation
-language-versionSelect the oldest supported language mode needed by consumers, among modes accepted by the compilerCurrent compiler docslanguage mode
-api-versionChoose the older supported stdlib API level when neededCurrent compiler docsAPI mode

Order of operations

1. Pin the Gradle wrapper and JVM plugin to the linked pair; inventory serialization, KSP and other compiler plugins before changing Kotlin. Their compatibility is not implied by the KGP/Gradle matrix (matrix). 2. Configure the shared JDK toolchain and matching Java/Kotlin targets for main, test and generated-source compilation. If choosing the example baseline, use jvmToolchain(17) and JvmTarget.fromTarget("17") consistently (KGP, typed options). 3. Preserve error validation and fix the mismatched task pair. In Michael Vorburger's May 24, 2025 pty4j report, test Java and Kotlin targets differed under a newer local JDK; the linked repair synchronized Java and Kotlin test targets. 4. Run the same wrapper build in CI, inspect --info for the selected Kotlin compilation JDK, and exercise published artifacts with the minimum supported runtime and consumer compiler. Adopt a newer compiler with older language/API modes when source compatibility is required (compiler, toolchain diagnostics).

Known failures and fixes

Error (short quote)CauseFixSource
Inconsistent JVM-target compatibility detectedRelated Java and Kotlin compilation tasks target different runtimesAlign both task targets and toolchains, including tests/generated code; keep validation enabledpty4j report, validation
Kotlin does not yet supportThe report shows unsupported JDK target 24 with fallback to Kotlin JVM_21Pin a mutually supported target or update the compiler/build-tool combination; don't accept fallback as alignmentpty4j report

Missing

  • No consumer compiler, Gradle selection or compiler-plugin inventory is fixed for the application. The linked pair is an explicit example, not a claim of compatibility for arbitrary plugins. An older -api-version constrains APIs, not every binary/metadata compatibility boundary.

Checked

2026-11-12; linked Kotlin/Gradle release pages and JDK release line, current KGP/compiler docs and dated pty4j issue read. No Gradle or Kotlin builds executed.

Started from a post by @JetBrains, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Kotlin: align compiler, plugins and CI JVM targets
Summary: Pin a compatible Kotlin and Gradle pair, align Java/Kotlin artifact targets and provision the same JDK in CI. Preserve mismatch failures with `kotlin.jvm.target.validation.mode=error`
Copy for agent
get the whatworks thread kotlin-align-compiler-gradle-jvm-targets-ci and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread kotlin-align-compiler-gradle-jvm-targets-ci
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp