Skip to content

Commit

Permalink
Migrate kotlinOptions to compilerOptions (#26)
Browse files Browse the repository at this point in the history
* [refactor/kotlinoptions-to-compileroptions] Migrate kotlinOptions to CompilerOptions

- Due to kotlinOptions function is depreacted at Kotlin 2.0

* Add comments that existed

* Fix Build Error
  • Loading branch information
l2hyunwoo authored May 25, 2024
1 parent debc883 commit 5738015
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> {
override fun apply(target: Project) {
Expand All @@ -16,6 +19,10 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = 34
}

extensions.getByType<KotlinAndroidProjectExtension>().apply {
configureKotlinAndroid(this)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> {
override fun apply(target: Project) {
Expand All @@ -27,6 +29,10 @@ class AndroidFeatureConventionPlugin : Plugin<Project> {
configureAndroidCompose(this)
defaultConfig.targetSdk = 34
}

extensions.getByType<KotlinAndroidProjectExtension>().apply {
configureKotlinAndroid(this)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> {
override fun apply(target: Project) {
Expand All @@ -16,6 +18,10 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = 34
}

extensions.getByType<KotlinAndroidProjectExtension>().apply {
configureKotlinAndroid(this)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

0 comments on commit 5738015

Please sign in to comment.