Ryan King
04/10/2024, 1:46 AMRyan King
04/10/2024, 1:47 AMamazoncorretto:21.0.2
. When targetting 21 I have no issues (via jvmToolchain(21)
and kotlinOptions { jvmTarget = 21 }
).
However, my project requires that in certain deployment situations to create earlier JVM compatible binaries. For example, target compatible with 20. Changing to jvmToolchain(20)
and kotlinOptions { jvmTarget = 20 }
results in gradle throwing me the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':compileKotlin'.
> Cannot find a Java installation on your machine matching this tasks requirements: {languageVersion=20, vendor=any, implementation=vendor-specific} for LINUX on x86_64.
> No locally installed toolchains match and toolchain download repositories have not been configured.
It is my understanding that the JDK should have no problem compiling for compatibility with 20, even if the only available JDK is 21. I assume there is some Gradle-foo I can do to make that happen.
Note: I have explicitly disabled gradle from automatically fetching needed JDKs in an effort to not have my CI server downloading a 300+mb blob for every build. I would rather set up multiple docker images, or modify my current one, to include multiple JDKs instead.
My current build setup uses:
gradle-8.7
kotlin-1.9.23 (targeting language version 1.9)
java-21 (trying to also target 20 in certain situations)
amazoncorretto:21.0.2 (for build environment)Ryan King
04/10/2024, 2:09 AMkotlin {
jvmToolchain(21) // Installed JDK version
}
compileKotlin {
kotlinOptions {
jvmTarget = 20 // Target JDK
}
}
java {
sourceCompatibility = JavaVersion.toVersion(20) // Target JDK
targetCompatibility = JavaVersion.toVersion(20) // Target JDK
toolchain {
languageVersion = JavaLanguageVersion.of(21) // Installed JDK version
}
}
Inspecting the generated .class
files seems to indicate everything is compiled to target major version: 64
, which is what I am looking for.Chris Lee
04/10/2024, 4:14 AMNo locally installed toolchains match and toolchain download repositories have not been configured.…Java 20 is not installed on that container, and you haven’t configured Gradle to download JVMs. Try this in `settings.gradle.kts`:
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}
Chris Lee
04/10/2024, 4:16 AMmateusz.kwiecinski
04/10/2024, 8:07 AMfoojay-resolver-convention
pluginmateusz.kwiecinski
04/10/2024, 8:07 AMrelease
option - documentationmateusz.kwiecinski
04/10/2024, 8:12 AMRyan King
04/10/2024, 4:00 PM