From 4916bc6385d91c6960da4aac637ab15463cc8b56 Mon Sep 17 00:00:00 2001 From: skydoves Date: Wed, 22 May 2024 23:11:56 +0900 Subject: [PATCH] Migrate to Kotlin 2.0.0 and Compose compiler --- app/build.gradle.kts | 5 +-- baselineprofile/build.gradle.kts | 1 + ...droidApplicationComposeConventionPlugin.kt | 1 + .../kotlin/AndroidFeatureConventionPlugin.kt | 1 + .../AndroidLibraryComposeConventionPlugin.kt | 1 + .../pokedex/compose/AndroidCompose.kt | 32 ------------------- build.gradle.kts | 1 + gradle/libs.versions.toml | 6 ++-- 8 files changed, 11 insertions(+), 37 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index d601514..7edf322 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -68,8 +68,9 @@ android { buildConfig = true } - composeOptions { - kotlinCompilerExtensionVersion = libs.versions.androidxComposeCompiler.get() + composeCompiler { + enableStrongSkippingMode = true + reportsDestination = layout.buildDirectory.dir("compose_compiler") } hilt { diff --git a/baselineprofile/build.gradle.kts b/baselineprofile/build.gradle.kts index dc6a109..7cf499c 100644 --- a/baselineprofile/build.gradle.kts +++ b/baselineprofile/build.gradle.kts @@ -1,6 +1,7 @@ plugins { alias(libs.plugins.android.test) alias(libs.plugins.kotlin.android) + alias(libs.plugins.compose.compiler) alias(libs.plugins.baselineprofile) id("skydoves.pokedex.spotless") } diff --git a/build-logic/convention/src/main/kotlin/AndroidApplicationComposeConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidApplicationComposeConventionPlugin.kt index 3aef2c8..b3f1be3 100644 --- a/build-logic/convention/src/main/kotlin/AndroidApplicationComposeConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidApplicationComposeConventionPlugin.kt @@ -8,6 +8,7 @@ class AndroidApplicationComposeConventionPlugin : Plugin { override fun apply(target: Project) { with(target) { pluginManager.apply("com.android.application") + pluginManager.apply("org.jetbrains.kotlin.plugin.compose") val extension = extensions.getByType() configureAndroidCompose(extension) } diff --git a/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt index b7972ef..536df53 100644 --- a/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt @@ -15,6 +15,7 @@ class AndroidFeatureConventionPlugin : Plugin { pluginManager.apply { apply("com.android.library") apply("org.jetbrains.kotlin.android") + apply("org.jetbrains.kotlin.plugin.compose") } dependencies { diff --git a/build-logic/convention/src/main/kotlin/AndroidLibraryComposeConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidLibraryComposeConventionPlugin.kt index 6fc0f4a..fc7f2ab 100644 --- a/build-logic/convention/src/main/kotlin/AndroidLibraryComposeConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidLibraryComposeConventionPlugin.kt @@ -8,6 +8,7 @@ class AndroidLibraryComposeConventionPlugin : Plugin { override fun apply(target: Project) { with(target) { pluginManager.apply("com.android.library") + pluginManager.apply("org.jetbrains.kotlin.plugin.compose") val extension = extensions.getByType() configureAndroidCompose(extension) } diff --git a/build-logic/convention/src/main/kotlin/com/skydoves/pokedex/compose/AndroidCompose.kt b/build-logic/convention/src/main/kotlin/com/skydoves/pokedex/compose/AndroidCompose.kt index a761771..3a59cb0 100644 --- a/build-logic/convention/src/main/kotlin/com/skydoves/pokedex/compose/AndroidCompose.kt +++ b/build-logic/convention/src/main/kotlin/com/skydoves/pokedex/compose/AndroidCompose.kt @@ -12,41 +12,9 @@ import org.gradle.kotlin.dsl.getByType internal fun Project.configureAndroidCompose( commonExtension: CommonExtension<*, *, *, *, *, *>, ) { - val libs = extensions.getByType().named("libs") - commonExtension.apply { buildFeatures { compose = true } - - composeOptions { - kotlinCompilerExtensionVersion = libs.findVersion("androidxComposeCompiler").get().toString() - } - - kotlinOptions { - freeCompilerArgs = freeCompilerArgs + buildComposeMetricsParameters() - } - } -} - -private fun Project.buildComposeMetricsParameters(): List = buildList { - val enableMetricsProvider = project.providers.gradleProperty("enableComposeCompilerMetrics") - val enableMetrics = (enableMetricsProvider.orNull == "true") - if (enableMetrics) { - val metricsFolder = project.layout.buildDirectory.dir("compose-metrics").get() - add("-P") - add( - "plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=$metricsFolder" - ) - } - - val enableReportsProvider = project.providers.gradleProperty("enableComposeCompilerReports") - val enableReports = (enableReportsProvider.orNull == "true") - if (enableReports) { - val reportsFolder = project.layout.buildDirectory.dir("compose-reports").get() - add("-P") - add( - "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=$reportsFolder" - ) } } diff --git a/build.gradle.kts b/build.gradle.kts index dc70628..3eb00f6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,6 +6,7 @@ plugins { alias(libs.plugins.kotlin.parcelize) apply false alias(libs.plugins.kotlinx.serialization) apply false alias(libs.plugins.ksp) apply false + alias(libs.plugins.compose.compiler) apply false alias(libs.plugins.hilt.plugin) apply false alias(libs.plugins.spotless) alias(libs.plugins.baselineprofile) apply false diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ce3dffc..912d934 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ [versions] agp = "8.4.0" -kotlin = "1.9.24" -ksp = "1.9.24-1.0.20" +kotlin = "2.0.0" +ksp = "2.0.0-1.0.21" kotlinxImmutable = "0.3.7" androidxActivity = "1.9.0" androidxCore = "1.13.1" @@ -10,7 +10,6 @@ androidxRoom = "2.6.1" androidxArchCore = "2.2.0" androidXStartup = "1.1.1" androidxCompose = "1.7.0-beta01" -androidxComposeCompiler = "1.5.14" androidxComposeMaterial3 = "1.3.0-beta01" androidxNavigation = "2.8.0-beta01" androidxHiltNavigationCompose = "1.2.0" @@ -106,6 +105,7 @@ kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = spotless = { id = "com.diffplug.spotless", version.ref = "spotless" } hilt-plugin = { id = "com.google.dagger.hilt.android", version.ref = "hilt" } baselineprofile = { id = "androidx.baselineprofile", version.ref = "baselineprofile" } +compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } [bundles] retrofitBundle = ["retrofit", "retrofit-kotlinx-serialization", "okhttp-logging-interceptor"]