diff --git a/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt index 1ecd0a5..75113ae 100644 --- a/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt @@ -3,6 +3,9 @@ import com.skydoves.pokedex.compose.configureKotlinAndroid import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.getByType +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension class AndroidApplicationConventionPlugin : Plugin { override fun apply(target: Project) { @@ -16,6 +19,10 @@ class AndroidApplicationConventionPlugin : Plugin { configureKotlinAndroid(this) defaultConfig.targetSdk = 34 } + + extensions.getByType().apply { + configureKotlinAndroid(this) + } } } } diff --git a/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt index d6de085..e25b3c0 100644 --- a/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt @@ -5,6 +5,8 @@ import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.dependencies +import org.gradle.kotlin.dsl.getByType +import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension class AndroidFeatureConventionPlugin : Plugin { override fun apply(target: Project) { @@ -27,6 +29,10 @@ class AndroidFeatureConventionPlugin : Plugin { configureAndroidCompose(this) defaultConfig.targetSdk = 34 } + + extensions.getByType().apply { + configureKotlinAndroid(this) + } } } } diff --git a/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt index 3efc91d..c15b887 100644 --- a/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt @@ -3,6 +3,8 @@ import com.skydoves.pokedex.compose.configureKotlinAndroid import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.getByType +import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension class AndroidLibraryConventionPlugin : Plugin { override fun apply(target: Project) { @@ -16,6 +18,10 @@ class AndroidLibraryConventionPlugin : Plugin { configureKotlinAndroid(this) defaultConfig.targetSdk = 34 } + + extensions.getByType().apply { + configureKotlinAndroid(this) + } } } } diff --git a/build-logic/convention/src/main/kotlin/com/skydoves/pokedex/compose/KotlinAndroid.kt b/build-logic/convention/src/main/kotlin/com/skydoves/pokedex/compose/KotlinAndroid.kt index 1a64b8c..7412d95 100644 --- a/build-logic/convention/src/main/kotlin/com/skydoves/pokedex/compose/KotlinAndroid.kt +++ b/build-logic/convention/src/main/kotlin/com/skydoves/pokedex/compose/KotlinAndroid.kt @@ -3,11 +3,8 @@ package com.skydoves.pokedex.compose 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.dependencies -import org.gradle.kotlin.dsl.getByType -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension /** * Configure base Kotlin with Android options @@ -30,28 +27,34 @@ internal fun Project.configureKotlinAndroid( lint { abortOnError = false } + } +} - kotlinOptions { +internal fun Project.configureKotlinAndroid( + extension: KotlinAndroidProjectExtension, +) { + extension.apply { + compilerOptions { // Treat all Kotlin warnings as errors (disabled by default) - allWarningsAsErrors = properties["warningsAsErrors"] as? Boolean ?: false - - freeCompilerArgs = freeCompilerArgs + listOf( - "-Xcontext-receivers", - "-opt-in=kotlin.RequiresOptIn", - // Enable experimental coroutines APIs, including Flow - "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", - // Enable experimental compose APIs - "-opt-in=androidx.compose.material3.ExperimentalMaterial3Api", - "-opt-in=androidx.lifecycle.compose.ExperimentalLifecycleComposeApi", - "-opt-in=androidx.compose.animation.ExperimentalSharedTransitionApi", + allWarningsAsErrors.set( + properties["warningsAsErrors"] as? Boolean ?: false + ) + + freeCompilerArgs.set( + freeCompilerArgs.getOrElse(emptyList()) + listOf( + "-Xcontext-receivers", + "-Xopt-in=kotlin.RequiresOptIn", + // Enable experimental coroutines APIs, including Flow + "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", + // Enable experimental compose APIs + "-Xopt-in=androidx.compose.material3.ExperimentalMaterial3Api", + "-Xopt-in=androidx.lifecycle.compose.ExperimentalLifecycleComposeApi", + "-Xopt-in=androidx.compose.animation.ExperimentalSharedTransitionApi", + ) ) // Set JVM target to 17 - jvmTarget = JavaVersion.VERSION_17.toString() + jvmTarget.set(JvmTarget.JVM_17) } } } - -fun CommonExtension<*, *, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) { - (this as ExtensionAware).extensions.configure("kotlinOptions", block) -}