Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate kotlinOptions to compilerOptions #26

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading