Configure jvmToolchain for Android projects

pull/583/head
Simon Marquis 2 years ago
parent 803e64be53
commit ea7bcf33c5

@ -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<Project> {
apply("org.jetbrains.kotlin.android")
}
configureKotlinAndroidToolchain()
extensions.configure<ApplicationExtension> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = 33

@ -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<Project> {
apply("org.jetbrains.kotlin.android")
}
configureKotlinAndroidToolchain()
extensions.configure<LibraryExtension> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = 33

@ -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<KotlinAndroidProjectExtension> {
jvmToolchain(11)
}
}

Loading…
Cancel
Save