From 01db3ef36d9d86ced8991082740e7d1984b432a0 Mon Sep 17 00:00:00 2001 From: Philipp Keck Date: Sun, 29 Jan 2023 11:53:19 +0100 Subject: [PATCH] Use JVM toolchain instead of Kotlin jvmTarget This [new Gradle feature](https://kotlinlang.org/docs/gradle-configure-project.html#gradle-java-toolchains-support) makes Gradle install the respective JDK/JRE instead of just using whatever JVM Gradle itself happens to run under. On my machine, that would be JVM 11, which leads to errors like `class file has wrong version 61.0, should be 55.0` when Dagger-generated Java files (like factories) try to interact with Kotlin-compiled classes. The `compilerOptions.jvmTarget` is then implied. --- build.gradle.kts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index c496664..4ed51e9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -53,8 +53,13 @@ tasks.test { } } +kotlin { + jvmToolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } +} + tasks.withType { - kotlinOptions.jvmTarget = "17" kotlinOptions.allWarningsAsErrors = true kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn" }