Skip to content

Commit

Permalink
Merge pull request #289 from taeheeL/refactor/kotlin-options-deprecated
Browse files Browse the repository at this point in the history
Migration kotlinOptions to compilerOptions
  • Loading branch information
skydoves authored Nov 5, 2024
2 parents 6053394 + 03308fd commit 269b084
Showing 1 changed file with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<KotlinCompile>().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)
}

0 comments on commit 269b084

Please sign in to comment.