From 570f8adf8f4f289cc212298bcaa4301bea846a1a Mon Sep 17 00:00:00 2001 From: Gerard Paligot Date: Fri, 24 Nov 2023 22:32:46 +0100 Subject: [PATCH] refactor: migrate Compose to Compose multiplatform. --- build-logic/build.gradle.kts | 4 --- .../extensions/LibraryExtensionExt.kt | 21 ---------------- .../io/openfeedback/plugins/AppPlugin.kt | 3 --- .../plugins/ComposeLibraryPlugin.kt | 25 ------------------- build.gradle.kts | 3 ++- libs.versions.toml | 10 ++------ openfeedback-m2/build.gradle.kts | 11 ++++---- openfeedback-m3/build.gradle.kts | 10 ++++---- openfeedback-viewmodel/build.gradle.kts | 8 +++--- sample-app/build.gradle.kts | 6 ++--- 10 files changed, 22 insertions(+), 79 deletions(-) delete mode 100644 build-logic/src/main/kotlin/io/openfeedback/plugins/ComposeLibraryPlugin.kt diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index 0fd62ab..77fc0d1 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -26,10 +26,6 @@ gradlePlugin { id = "io.openfeedback.plugins.lib.multiplatform" implementationClass = "io.openfeedback.plugins.MultiplatformPlugin" } - register("io.openfeedback.plugins.compose.lib") { - id = "io.openfeedback.plugins.compose.lib" - implementationClass = "io.openfeedback.plugins.ComposeLibraryPlugin" - } register("io.openfeedback.plugins.publishing") { id = "io.openfeedback.plugins.publishing" implementationClass = "io.openfeedback.plugins.PublishingPlugin" diff --git a/build-logic/src/main/kotlin/io/openfeedback/extensions/LibraryExtensionExt.kt b/build-logic/src/main/kotlin/io/openfeedback/extensions/LibraryExtensionExt.kt index 40604f1..06ee97d 100644 --- a/build-logic/src/main/kotlin/io/openfeedback/extensions/LibraryExtensionExt.kt +++ b/build-logic/src/main/kotlin/io/openfeedback/extensions/LibraryExtensionExt.kt @@ -4,10 +4,6 @@ package io.openfeedback.extensions 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.kotlin.dsl.dependencies -import org.gradle.kotlin.dsl.getByType internal fun CommonExtension<*, *, *, *, *>.configureKotlinAndroid() { compileSdk = 34 @@ -21,20 +17,3 @@ internal fun CommonExtension<*, *, *, *, *>.configureKotlinAndroid() { targetCompatibility = JavaVersion.VERSION_17 } } - -internal fun CommonExtension<*, *, *, *, *>.configureAndroidCompose(project: Project) { - val libs = project.extensions.getByType().named("libs") - - buildFeatures { - compose = true - } - - composeOptions { - kotlinCompilerExtensionVersion = libs.findVersion("androidx_compose_compiler").get().toString() - } - - project.dependencies { - add("debugImplementation", "androidx.customview:customview-poolingcontainer:1.0.0") - add("debugImplementation", "androidx.savedstate:savedstate-ktx:1.2.0") - } -} diff --git a/build-logic/src/main/kotlin/io/openfeedback/plugins/AppPlugin.kt b/build-logic/src/main/kotlin/io/openfeedback/plugins/AppPlugin.kt index 29a01f6..1889d2d 100644 --- a/build-logic/src/main/kotlin/io/openfeedback/plugins/AppPlugin.kt +++ b/build-logic/src/main/kotlin/io/openfeedback/plugins/AppPlugin.kt @@ -1,7 +1,6 @@ package io.openfeedback.plugins import com.android.build.gradle.internal.dsl.BaseAppModuleExtension -import io.openfeedback.extensions.configureAndroidCompose import io.openfeedback.extensions.configureKotlinAndroid import io.openfeedback.extensions.configureKotlinCompiler import org.gradle.api.Plugin @@ -14,10 +13,8 @@ class AppPlugin : Plugin { apply("com.android.application") apply("org.jetbrains.kotlin.android") } - target.extensions.configure { configureKotlinAndroid() - configureAndroidCompose(target) } target.tasks.configureKotlinCompiler() } diff --git a/build-logic/src/main/kotlin/io/openfeedback/plugins/ComposeLibraryPlugin.kt b/build-logic/src/main/kotlin/io/openfeedback/plugins/ComposeLibraryPlugin.kt deleted file mode 100644 index 3be1749..0000000 --- a/build-logic/src/main/kotlin/io/openfeedback/plugins/ComposeLibraryPlugin.kt +++ /dev/null @@ -1,25 +0,0 @@ -package io.openfeedback.plugins - -import com.android.build.gradle.LibraryExtension -import io.openfeedback.extensions.configureAndroidCompose -import io.openfeedback.extensions.configureKotlinAndroid -import io.openfeedback.extensions.configureKotlinCompiler -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.kotlin.dsl.configure - -class ComposeLibraryPlugin : Plugin { - override fun apply(target: Project) { - with(target.pluginManager) { - apply("com.android.library") - apply("org.jetbrains.kotlin.android") - } - - target.extensions.configure { - configureKotlinAndroid() - configureAndroidCompose(target) - defaultConfig.targetSdk = 34 - } - target.tasks.configureKotlinCompiler() - } -} diff --git a/build.gradle.kts b/build.gradle.kts index cdaa3b3..afe635e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,8 +1,9 @@ import io.openfeedback.extensions.configureRoot plugins { - id("io.openfeedback.plugins.compose.lib") apply false + id("io.openfeedback.plugins.lib") apply false alias(libs.plugins.moko.resources.generator) apply false + alias(libs.plugins.jetbrains.compose) apply false } version = "0.1.2" diff --git a/libs.versions.toml b/libs.versions.toml index 838193d..363259d 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -3,9 +3,8 @@ kotlin_lang = "1.9.10" kotlin_coroutines = "1.7.3" kotlinx_datetime = "0.4.1" kotlinx_serialization = "1.6.0" +jetbrains_compose = "1.5.1" androidx_core = "1.12.0" -androidx_compose_bom = "2023.10.01" -androidx_compose_compiler = "1.5.3" androidx_lifecycle = "2.6.2" firebase_common = "20.4.2" firebase_firestore = "24.9.1" @@ -33,15 +32,10 @@ gitlive_auth = { module = "dev.gitlive:firebase-auth", version.ref = "gitlive_fi gitlive_common = { module = "dev.gitlive:firebase-common", version.ref = "gitlive_firebase" } androidx_core = { module = "androidx.core:core-ktx", version.ref = "androidx_core" } -androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "androidx_compose_bom" } -androidx_compose_material = { module = "androidx.compose.material:material" } -androidx_compose_material3 = { module = "androidx.compose.material3:material3" } -androidx_compose_ui = { module = "androidx.compose.ui:ui" } -androidx_compose_runtime = { module = "androidx.compose.runtime:runtime" } -androidx_compose_uitooling = { module = "androidx.compose.ui:ui-tooling" } androidx_lifecycle_viewmodel_compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx_lifecycle" } moko_resources = { module = "dev.icerock.moko:resources", version.ref = "moko_resources"} [plugins] moko_resources_generator = { id = "dev.icerock.mobile.multiplatform-resources", version.ref = "moko_resources" } +jetbrains_compose = { id = "org.jetbrains.compose", version.ref = "jetbrains_compose" } diff --git a/openfeedback-m2/build.gradle.kts b/openfeedback-m2/build.gradle.kts index 821ed7d..c0a6350 100644 --- a/openfeedback-m2/build.gradle.kts +++ b/openfeedback-m2/build.gradle.kts @@ -1,7 +1,8 @@ plugins { - id("io.openfeedback.plugins.compose.lib") + id("io.openfeedback.plugins.lib") id("io.openfeedback.plugins.publishing") + alias(libs.plugins.jetbrains.compose) } android { @@ -15,9 +16,9 @@ openfeedback { dependencies { api(projects.openfeedback) api(projects.openfeedbackViewmodel) + implementation(libs.androidx.lifecycle.viewmodel.compose) - implementation(platform(libs.androidx.compose.bom)) - implementation(libs.androidx.compose.material) - implementation(libs.androidx.compose.ui) - implementation(libs.androidx.compose.uitooling) + implementation(compose.material) + implementation(compose.ui) + implementation(compose.uiTooling) } diff --git a/openfeedback-m3/build.gradle.kts b/openfeedback-m3/build.gradle.kts index 833eb9d..a56cfe5 100644 --- a/openfeedback-m3/build.gradle.kts +++ b/openfeedback-m3/build.gradle.kts @@ -1,7 +1,8 @@ plugins { - id("io.openfeedback.plugins.compose.lib") + id("io.openfeedback.plugins.lib") id("io.openfeedback.plugins.publishing") + alias(libs.plugins.jetbrains.compose) } android { @@ -17,8 +18,7 @@ dependencies { api(projects.openfeedbackViewmodel) implementation(libs.androidx.lifecycle.viewmodel.compose) - implementation(platform(libs.androidx.compose.bom)) - implementation(libs.androidx.compose.material3) - implementation(libs.androidx.compose.ui) - implementation(libs.androidx.compose.uitooling) + implementation(compose.material3) + implementation(compose.ui) + implementation(compose.uiTooling) } diff --git a/openfeedback-viewmodel/build.gradle.kts b/openfeedback-viewmodel/build.gradle.kts index 07bd4c0..e92adbc 100644 --- a/openfeedback-viewmodel/build.gradle.kts +++ b/openfeedback-viewmodel/build.gradle.kts @@ -1,7 +1,7 @@ - plugins { - id("io.openfeedback.plugins.compose.lib") + id("io.openfeedback.plugins.lib") id("io.openfeedback.plugins.publishing") + alias(libs.plugins.jetbrains.compose) } android { @@ -15,6 +15,6 @@ openfeedback { dependencies { implementation(projects.openfeedback) implementation(libs.androidx.lifecycle.viewmodel.compose) - implementation(platform(libs.androidx.compose.bom)) - implementation(libs.androidx.compose.runtime) + implementation(compose.runtime) + } \ No newline at end of file diff --git a/sample-app/build.gradle.kts b/sample-app/build.gradle.kts index fa9ec33..f736780 100644 --- a/sample-app/build.gradle.kts +++ b/sample-app/build.gradle.kts @@ -1,5 +1,6 @@ plugins { id("io.openfeedback.plugins.app") + alias(libs.plugins.jetbrains.compose) } android { @@ -15,9 +16,8 @@ dependencies { implementation("androidx.appcompat:appcompat:1.5.1") implementation("androidx.activity:activity-compose:1.7.0-alpha02") - implementation(platform(libs.androidx.compose.bom)) - implementation(libs.androidx.compose.material) - implementation(libs.androidx.compose.material3) + implementation(compose.material) + implementation(compose.material3) implementation(projects.openfeedbackM2) implementation(projects.openfeedbackM3)