From ea7bcf33c594b0687c21a4e9a65c3c33c763b00f Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Sat, 11 Feb 2023 11:52:54 +0100 Subject: [PATCH 1/2] Configure jvmToolchain for Android projects --- .../main/kotlin/AndroidApplicationConventionPlugin.kt | 2 ++ .../src/main/kotlin/AndroidLibraryConventionPlugin.kt | 2 ++ .../google/samples/apps/nowinandroid/KotlinAndroid.kt | 11 +++++++++++ 3 files changed, 15 insertions(+) diff --git a/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt index 6bc5f9f9e..e0efe511b 100644 --- a/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt @@ -19,6 +19,7 @@ import com.android.build.api.dsl.ApplicationExtension import com.google.samples.apps.nowinandroid.configureFlavors import com.google.samples.apps.nowinandroid.configureGradleManagedDevices import com.google.samples.apps.nowinandroid.configureKotlinAndroid +import com.google.samples.apps.nowinandroid.configureKotlinAndroidToolchain import com.google.samples.apps.nowinandroid.configurePrintApksTask import org.gradle.api.Plugin import org.gradle.api.Project @@ -32,6 +33,7 @@ class AndroidApplicationConventionPlugin : Plugin { apply("org.jetbrains.kotlin.android") } + configureKotlinAndroidToolchain() extensions.configure { configureKotlinAndroid(this) defaultConfig.targetSdk = 33 diff --git a/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt index 842873bae..c0e269243 100644 --- a/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt @@ -20,6 +20,7 @@ import com.android.build.gradle.LibraryExtension import com.google.samples.apps.nowinandroid.configureFlavors import com.google.samples.apps.nowinandroid.configureGradleManagedDevices import com.google.samples.apps.nowinandroid.configureKotlinAndroid +import com.google.samples.apps.nowinandroid.configureKotlinAndroidToolchain import com.google.samples.apps.nowinandroid.configurePrintApksTask import org.gradle.api.Plugin import org.gradle.api.Project @@ -37,6 +38,7 @@ class AndroidLibraryConventionPlugin : Plugin { apply("org.jetbrains.kotlin.android") } + configureKotlinAndroidToolchain() extensions.configure { configureKotlinAndroid(this) defaultConfig.targetSdk = 33 diff --git a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/KotlinAndroid.kt b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/KotlinAndroid.kt index da0cab531..2b5d1c354 100644 --- a/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/KotlinAndroid.kt +++ b/build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/KotlinAndroid.kt @@ -21,9 +21,11 @@ import org.gradle.api.JavaVersion import org.gradle.api.Project import org.gradle.api.artifacts.VersionCatalogsExtension import org.gradle.api.plugins.ExtensionAware +import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.dependencies import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.provideDelegate +import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions /** @@ -74,3 +76,12 @@ internal fun Project.configureKotlinAndroid( fun CommonExtension<*, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) { (this as ExtensionAware).extensions.configure("kotlinOptions", block) } + +/** + * Configure Kotlin's jvm toolchain for Android projects + */ +internal fun Project.configureKotlinAndroidToolchain() { + extensions.configure { + jvmToolchain(11) + } +} From e1f8c51c056ddb9a6b6c16837537a54ed91c588d Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Sat, 11 Feb 2023 11:53:36 +0100 Subject: [PATCH 2/2] Configure jvmToolchain on the single Kotlin jvm project --- core/model/build.gradle.kts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/model/build.gradle.kts b/core/model/build.gradle.kts index edfcc4596..eec8d82ab 100644 --- a/core/model/build.gradle.kts +++ b/core/model/build.gradle.kts @@ -19,6 +19,10 @@ plugins { id("kotlin") } +kotlin { + jvmToolchain(11) +} + dependencies { implementation(libs.kotlinx.datetime) } \ No newline at end of file