Gavin Ray
01/10/2023, 6:27 PMjavac
right, at a 10,000ft view, so if there is a java compiler on the system capable of compiling those versions why can't Gradle use it?
For instance, why can't I run the Gradle daemon with JDK17, and ask it to use JDK21 to compile my .java
files 🤔mbonnin
01/10/2023, 6:51 PMmbonnin
01/10/2023, 6:52 PMChris Lee
01/10/2023, 6:53 PMChris Lee
01/10/2023, 7:04 PMGavin Ray
01/10/2023, 7:40 PM8.0-rc
Gavin Ray
01/10/2023, 7:40 PMGavin Ray
01/10/2023, 7:44 PMjava {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
2023-01-10T14:43:46.776-0500 [ERROR] [system.err] java.lang.UnsupportedClassVersionError: postgres/wire/protocol/App has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 63.0
mbonnin
01/10/2023, 7:56 PMmbonnin
01/10/2023, 7:57 PM--stacktrace
?mbonnin
01/10/2023, 7:57 PMmbonnin
01/10/2023, 8:07 PMmbonnin
01/10/2023, 8:08 PMmbonnin
01/10/2023, 8:09 PMplugins {
id("java")
id("application")
}
repositories {
mavenCentral()
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
application {
mainClass.set("com.example.Main")
}
mbonnin
01/10/2023, 8:09 PMmbonnin
01/10/2023, 8:09 PMsdk uninstall java 21.ea.4-open
)tapchicoma
01/11/2023, 9:05 AMtasks.withType<UsesKotlinJavaToolchain>().configureEach {
kotlinJavaToolchain.jdk.use(
"/path/to/local/jdk", // Put a path to your JDK
JavaVersion.<LOCAL_JDK_VERSION> // For example, JavaVersion.17
)
}
Note though that this will not configure any Java/Groovy etc tasks with this toolchain.Gavin Ray
01/20/2023, 9:01 PMjava {
toolchain {
// Tell Gradle itself to use JDK19
languageVersion.set(JavaLanguageVersion.of(19))
}
}
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
val JDK_VERSION = JavaLanguageVersion.of(21)
val JDK_FLAGS = listOf("--enable-preview")
val JDK_21_COMPILER: Provider<JavaCompiler> = javaToolchains.compilerFor {
languageVersion.set(JDK_VERSION)
}
val JDK_21_LAUNCHER: Provider<JavaLauncher> = javaToolchains.launcherFor {
languageVersion.set(JDK_VERSION)
}
tasks.withType<JavaCompile>().configureEach {
javaCompiler.set(JDK_21_COMPILER)
options.isIncremental = true
options.isFork = true
options.compilerArgs = JDK_FLAGS
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
javaLauncher.set(JDK_21_LAUNCHER)
jvmArgs = JDK_FLAGS
}
tasks.withType<JavaExec>().configureEach {
javaLauncher.set(JDK_21_LAUNCHER)
jvmArgs = JDK_FLAGS
}