From 03308fd88c3865c5f5ba0166f2be0e8e8bc7be1b Mon Sep 17 00:00:00 2001 From: HaeTi Date: Tue, 5 Nov 2024 04:14:19 +0900 Subject: [PATCH] Migration kotlinOptions to compilerOptions --- .../getstream/whatsappclone/KotlinAndroid.kt | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/build-logic/convention/src/main/kotlin/io/getstream/whatsappclone/KotlinAndroid.kt b/build-logic/convention/src/main/kotlin/io/getstream/whatsappclone/KotlinAndroid.kt index f417776..72745c2 100644 --- a/build-logic/convention/src/main/kotlin/io/getstream/whatsappclone/KotlinAndroid.kt +++ b/build-logic/convention/src/main/kotlin/io/getstream/whatsappclone/KotlinAndroid.kt @@ -4,7 +4,11 @@ import com.android.build.api.dsl.CommonExtension import org.gradle.api.JavaVersion import org.gradle.api.Project import org.gradle.api.plugins.ExtensionAware +import org.gradle.kotlin.dsl.provideDelegate +import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile /** * Configure base Kotlin with Android options @@ -28,26 +32,26 @@ internal fun Project.configureKotlinAndroid( abortOnError = false } - kotlinOptions { - // Treat all Kotlin warnings as errors (disabled by default) - allWarningsAsErrors = properties["warningsAsErrors"] as? Boolean ?: false - - freeCompilerArgs = freeCompilerArgs + listOf( - "-opt-in=kotlin.RequiresOptIn", - // Enable experimental coroutines APIs, including Flow - "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", - // Enable experimental compose APIs - "-opt-in=com.google.accompanist.pager.ExperimentalPagerApi", - "-opt-in=androidx.compose.material3.ExperimentalMaterial3Api", - "-opt-in=androidx.lifecycle.compose.ExperimentalLifecycleComposeApi", - ) - - // Set JVM target to 11 - jvmTarget = JavaVersion.VERSION_17.toString() + tasks.withType().configureEach { + compilerOptions { + val warningsAsErrors: String? by project + // Treat all Kotlin warnings as errors (disabled by default) + allWarningsAsErrors.set(warningsAsErrors.toBoolean()) + + freeCompilerArgs.addAll( + listOf( + "-opt-in=kotlin.RequiresOptIn", + // Enable experimental coroutines APIs, including Flow + "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", + // Enable experimental compose APIs + "-opt-in=com.google.accompanist.pager.ExperimentalPagerApi", + "-opt-in=androidx.compose.material3.ExperimentalMaterial3Api", + "-opt-in=androidx.lifecycle.compose.ExperimentalLifecycleComposeApi", + ) + ) + + jvmTarget.set(JvmTarget.JVM_17) + } } } } - -fun CommonExtension<*, *, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) { - (this as ExtensionAware).extensions.configure("kotlinOptions", block) -}