https://kotlinlang.org logo
#gradle
Title
# gradle
m

mbonnin

01/19/2023, 10:53 AM
I'm confused about https://kotlinlang.org/docs/gradle-configure-project.html#gradle-java-toolchains-support:
Copy code
When there is no explicit information about the jvmTarget value in the build script, its default value is null, and the compiler translates it to the default value 1.8. The targetCompatibility equals a current Gradle's JDK version
If the default value is
1.8
, how come
targetCompatibility
is Gradle's JDK? Is there a difference between
jvmTarget
and
targetCompatibility
?
t

tapchicoma

01/19/2023, 12:24 PM
JavaCompile
by default has
targetCompatibility
value set to current Gradle JDK version, while Kotlin
jvmTarget
is always
1.8
(but not with Gradle 8.+). So if you are running Gradle build with JDK 11 - your compiled Java and Kotlin classes will have different class version
m

mbonnin

01/19/2023, 12:25 PM
I'm trying Gradle 8 at the moment
t

tapchicoma

01/19/2023, 12:25 PM
From Gradle 8.0 both Java and Kotlin uses default toolchain (by default same as Gradle JDK) and configure accordingly
targetCompatiblity
and
jvmTarget
values
m

mbonnin

01/19/2023, 12:26 PM
I see . But looks like Android still forces java to 8 (but not Kotlin)
t

tapchicoma

01/19/2023, 12:26 PM
before Gradle 8 default toolchain is
null
leading to such difference
AGP has a bug, wait a sec
Actually bug is linked in the docs ) https://issuetracker.google.com/issues/260059413
m

mbonnin

01/19/2023, 12:28 PM
Ah yes, perfetc!
I need a flow chart of jvmTargets 😅
Thanks for the insights!
t

tapchicoma

01/19/2023, 12:29 PM
with Gradle 8 and fix in AGP it should be straightforward 😅
15 Views