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

Conversation

l2hyunwoo
Copy link
Contributor

@l2hyunwoo l2hyunwoo commented May 24, 2024

🎯 Goal

  • Migrate kotlinOptions to compilerOptions function due to kotlinOptions is deprecated.

🛠 Implementation details

  • I'd apply compilerOptions, but it is registered on KotlinAndroidProjectExtension, not BaseExtension. So I've to separate this code block to configureKotlinAndroid. So the result of migration is below.
// KotlinAndroid.kt

/*
* ETC
*/

// Newly added configuration function for `KotlinAndroidProjectExtension`
internal fun Project.configureKotlinAndroid(
  extension: KotlinAndroidProjectExtension,
) {
  extension.apply {
    compilerOptions {
      // Treat all Kotlin warnings as errors (disabled by default)
      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.set(JvmTarget.JVM_17)
    }
  }
}

// AndroidApplicationConventionPlugin
class AndroidApplicationConventionPlugin : Plugin<Project> {
  override fun apply(target: Project) {
    with(target) {
      // ...etc

      // Newly Added
      extensions.getByType<KotlinAndroidProjectExtension>().apply {
        configureKotlinAndroid(this)
      }
    }
  }
}

// Also same as Library, Feature convention plugin

✍️ Explain examples

Preparing a pull request for review

Ensure your change is properly formatted by running:

$ ./gradlew spotlessApply

Please correct any failures before requesting a review.

…CompilerOptions

- Due to kotlinOptions function is depreacted at Kotlin 2.0
@l2hyunwoo l2hyunwoo requested a review from skydoves as a code owner May 24, 2024 03:14
Copy link
Owner

@skydoves skydoves left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you for your contribution, @l2hyunwoo!

@skydoves skydoves merged commit 5738015 into skydoves:main May 25, 2024
2 checks passed
@l2hyunwoo l2hyunwoo deleted the feature/migrate-kotlinoptions-to-compileroptions branch May 25, 2024 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants