Skip to content

Commit b6f5079

Browse files
committed
docs: include the java {} block in the cross-compile toolchain snippet
1 parent 4be1a11 commit b6f5079

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

docs/architecture.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,22 +510,34 @@ All code targets Java 8 bytecode (`jvmTarget = "1.8"`). Specific implications:
510510

511511
Most modules compile against Java 8 bytecode, but two need a newer JDK: `sdk-transport-jdkhttp`
512512
targets 11 (`java.net.http.HttpClient` was finalised in JEP 321) and `sdk-async-virtualthreads`
513-
targets 21 (virtual threads). Each of those modules raises its target by overriding **two**
513+
targets 21 (virtual threads). Each of those modules raises its target by overriding **three**
514514
things in its own build script:
515515

516516
```kotlin
517517
kotlin {
518518
jvmToolchain(21) // which JDK compiles the module
519519
}
520520

521+
java {
522+
sourceCompatibility = JavaVersion.VERSION_21 // Java-source level
523+
targetCompatibility = JavaVersion.VERSION_21 // bytecode version `compileJava` emits
524+
toolchain {
525+
languageVersion.set(JavaLanguageVersion.of(21))
526+
}
527+
}
528+
521529
tasks.withType<KotlinCompile>().configureEach {
522530
compilerOptions {
523-
jvmTarget.set(JvmTarget.JVM_21) // which bytecode version it emits
531+
jvmTarget.set(JvmTarget.JVM_21) // bytecode version `compileKotlin` emits
524532
}
525533
}
526534
```
527535

528-
(`sdk-transport-jdkhttp` does the same with `11`/`JVM_11`.) **Both** overrides are mandatory.
536+
(`sdk-transport-jdkhttp` does the same with `11`/`VERSION_11`/`JVM_11`.) **All three** overrides
537+
are mandatory. The `java {}` block governs `compileJava` and keeps Gradle's JVM-target validation
538+
between `compileJava` and `compileKotlin` happy; a module that sets only the Kotlin toolchain and
539+
`jvmTarget` but omits the `java {}` block will trip that validation or compile its Java sources at
540+
the wrong level.
529541
The root build registers a `plugins.withId("org.jetbrains.kotlin.jvm")` callback that sets
530542
`jvmTarget` to `JVM_1_8` for every Kotlin module by default. A module that bumps only the
531543
toolchain — say to JDK 21 — but leaves `jvmTarget` at the inherited `1.8` will compile *against*

0 commit comments

Comments
 (0)