diff --git a/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt index 26b6951d3..0e2eaa397 100644 --- a/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt @@ -18,6 +18,7 @@ import com.android.build.api.dsl.ApplicationExtension import com.google.samples.apps.nowinandroid.configureGradleManagedDevices import com.android.build.api.variant.ApplicationAndroidComponentsExtension 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 @@ -31,6 +32,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 275a26620..2ffeae974 100644 --- a/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt @@ -19,6 +19,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 com.google.samples.apps.nowinandroid.disableUnnecessaryAndroidTests import org.gradle.api.Plugin @@ -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 65a734895..656a66329 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 @@ -20,10 +20,14 @@ import com.android.build.api.dsl.CommonExtension 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.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions import org.jetbrains.kotlin.gradle.tasks.KotlinCompile /** @@ -72,3 +76,16 @@ internal fun Project.configureKotlinAndroid( add("coreLibraryDesugaring", libs.findLibrary("android.desugarJdkLibs").get()) } } + +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) + } +} diff --git a/core/model/build.gradle.kts b/core/model/build.gradle.kts index d49c5b3ee..67ecf9006 100644 --- a/core/model/build.gradle.kts +++ b/core/model/build.gradle.kts @@ -18,6 +18,10 @@ plugins { id("kotlin") } +kotlin { + jvmToolchain(11) +} + dependencies { implementation(libs.kotlinx.datetime) } \ No newline at end of file