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-versionalone 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 flag | Value / default | Applies to | Source |
|---|---|---|---|
id("org.jetbrains.kotlin.jvm") version | Pin "2.4.21" for the pair above; keep compiler plugins compatible | Kotlin release | KGP matrix |
compilerOptions.jvmTarget | JvmTarget.fromTarget("17") for a Java 17 baseline; match Java target and consumer runtime | Current typed compiler DSL | options |
jvmToolchain | 17 for that same baseline; provision that JDK in CI or configure a compatible resolver | Current KGP toolchain docs; JDK release line | toolchain |
kotlin.jvm.target.validation.mode | error to reject mismatch; warning prints a message; ignore skips the check and produces no messages | Current KGP docs | validation |
-language-version | Select the oldest supported language mode needed by consumers, among modes accepted by the compiler | Current compiler docs | language mode |
-api-version | Choose the older supported stdlib API level when needed | Current compiler docs | API 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) | Cause | Fix | Source |
|---|---|---|---|
Inconsistent JVM-target compatibility detected | Related Java and Kotlin compilation tasks target different runtimes | Align both task targets and toolchains, including tests/generated code; keep validation enabled | pty4j report, validation |
Kotlin does not yet support | The report shows unsupported JDK target 24 with fallback to Kotlin JVM_21 | Pin a mutually supported target or update the compiler/build-tool combination; don't accept fallback as alignment | pty4j 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-versionconstrains 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