From cd4325e483d75f9ae1df8fc43a8353cf20c54775 Mon Sep 17 00:00:00 2001 From: Ryan Conway Date: Mon, 4 Nov 2024 18:16:20 +0700 Subject: [PATCH] [#586] Migrate to version catalog --- template-compose/app/build.gradle.kts | 69 +++------ template-compose/build.gradle.kts | 18 ++- .../buildSrc/src/main/java/Dependencies.kt | 71 --------- .../buildSrc/src/main/java/Plugins.kt | 16 -- .../buildSrc/src/main/java/Versions.kt | 39 ----- template-compose/data/build.gradle.kts | 45 ++---- template-compose/domain/build.gradle.kts | 22 +-- template-compose/gradle/libs.versions.toml | 141 ++++++++++++++++++ 8 files changed, 191 insertions(+), 230 deletions(-) delete mode 100644 template-compose/buildSrc/src/main/java/Dependencies.kt delete mode 100644 template-compose/buildSrc/src/main/java/Plugins.kt create mode 100644 template-compose/gradle/libs.versions.toml diff --git a/template-compose/app/build.gradle.kts b/template-compose/app/build.gradle.kts index 54b11d1ee..d97585565 100644 --- a/template-compose/app/build.gradle.kts +++ b/template-compose/app/build.gradle.kts @@ -1,12 +1,12 @@ import org.jetbrains.kotlin.konan.properties.loadProperties plugins { - id(Plugins.ANDROID_APPLICATION) - id(Plugins.KOTLIN_ANDROID) - id(Plugins.KOTLIN_KAPT) - id(Plugins.KOTLIN_PARCELIZE) - id(Plugins.HILT_ANDROID) - id(Plugins.KOVER) + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.kapt) + alias(libs.plugins.kotlin.parcelize) + alias(libs.plugins.hilt) + alias(libs.plugins.kover) } val signingProperties = loadProperties("$rootDir/signing.properties") @@ -133,54 +133,25 @@ dependencies { implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar")))) - with(Dependencies.AndroidX) { - implementation(CORE_KTX) - implementation(LIFECYCLE_RUNTIME_KTX) - implementation(LIFECYCLE_RUNTIME_COMPOSE) - implementation(DATASTORE_PREFERENCES) - } - - with(Dependencies.Compose) { - implementation(platform(BOM)) - implementation(UI) - debugImplementation(UI_TOOLING) - implementation(UI_TOOLING_PREVIEW) - implementation(MATERIAL) - implementation(NAVIGATION) - - implementation(ACCOMPANIST_PERMISSIONS) - } + implementation(libs.bundles.androidx) - with(Dependencies.Hilt) { - implementation(ANDROID) - implementation(NAVIGATION_COMPOSE) - kapt(COMPILER) - } + implementation(platform(libs.compose.bom)) + implementation(libs.bundles.compose) + debugImplementation(libs.compose.ui.tooling) - with(Dependencies.Log) { - implementation(TIMBER) + implementation(libs.bundles.hilt) + kapt(libs.hilt.compiler) - debugImplementation(CHUCKER) - releaseImplementation(CHUCKER_NO_OP) - } + implementation(libs.timber) + debugImplementation(libs.chucker) + releaseImplementation(libs.chucker.no.op) - with(Dependencies.Util) { - implementation(COMMON_KTX) - } + implementation(libs.nimble.common) - with(Dependencies.Test) { - // Unit test - testImplementation(COROUTINES) - testImplementation(JUNIT) - testImplementation(KOTEST) - testImplementation(MOCKK) - testImplementation(TURBINE) - - // UI test with Robolectric - testImplementation(platform(Dependencies.Compose.BOM)) - testImplementation(COMPOSE_UI_TEST_JUNIT) - testImplementation(ROBOLECTRIC) - } + testImplementation(libs.bundles.unitTest) + testImplementation(libs.test.turbine) + testImplementation(platform(libs.compose.bom)) + testImplementation(libs.bundles.implementationTest) } /* diff --git a/template-compose/build.gradle.kts b/template-compose/build.gradle.kts index 9319cd7ef..a921449aa 100644 --- a/template-compose/build.gradle.kts +++ b/template-compose/build.gradle.kts @@ -1,12 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id(Plugins.ANDROID_APPLICATION) version Versions.GRADLE apply false - id(Plugins.ANDROID_LIBRARY) version Versions.GRADLE apply false - id(Plugins.KOTLIN_JVM) version Versions.KOTLIN apply false - id(Plugins.KOTLIN_ANDROID) version Versions.KOTLIN apply false - id(Plugins.HILT_ANDROID) version Versions.HILT apply false - id(Plugins.DETEKT) version Versions.DETEKT - id(Plugins.KOVER) version Versions.KOVER + alias(libs.plugins.android.application) apply false + alias(libs.plugins.android.library) apply false + alias(libs.plugins.kotlin.jvm) apply false + alias(libs.plugins.kotlin.android) apply false + alias(libs.plugins.kotlin.kapt) apply false + alias(libs.plugins.kotlin.parcelize) apply false + alias(libs.plugins.hilt) apply false + alias(libs.plugins.detekt) + alias(libs.plugins.kover) } tasks.register("clean", Delete::class) { @@ -14,7 +16,7 @@ tasks.register("clean", Delete::class) { } detekt { - toolVersion = Versions.DETEKT + toolVersion = libs.versions.detekt.get() source = files( "app/src/main/java", diff --git a/template-compose/buildSrc/src/main/java/Dependencies.kt b/template-compose/buildSrc/src/main/java/Dependencies.kt deleted file mode 100644 index 06c295647..000000000 --- a/template-compose/buildSrc/src/main/java/Dependencies.kt +++ /dev/null @@ -1,71 +0,0 @@ -object Dependencies { - object AndroidX { - const val CORE_KTX = "androidx.core:core-ktx:${Versions.CORE_KTX}" - const val LIFECYCLE_RUNTIME_KTX = "androidx.lifecycle:lifecycle-runtime-ktx:${Versions.LIFECYCLE}" - const val LIFECYCLE_RUNTIME_COMPOSE = "androidx.lifecycle:lifecycle-runtime-compose:${Versions.LIFECYCLE}" - - const val DATASTORE_PREFERENCES = "androidx.datastore:datastore-preferences:${Versions.DATASTORE_PREFERENCES}" - const val SECURITY_CRYPTO = "androidx.security:security-crypto:${Versions.SECURITY_CRYPTO}" - } - - object Compose { - const val BOM = "androidx.compose:compose-bom:${Versions.COMPOSE_BOM}" - const val UI = "androidx.compose.ui:ui" - const val UI_TOOLING = "androidx.compose.ui:ui-tooling" - const val UI_TOOLING_PREVIEW = "androidx.compose.ui:ui-tooling-preview" - const val MATERIAL = "androidx.compose.material:material" - const val NAVIGATION = "androidx.navigation:navigation-compose:${Versions.COMPOSE_NAVIGATION}" - - const val ACCOMPANIST_PERMISSIONS = "com.google.accompanist:accompanist-permissions:${Versions.ACCOMPANIST}" - } - - object Hilt { - const val ANDROID = "com.google.dagger:hilt-android:${Versions.HILT}" - const val NAVIGATION_COMPOSE = "androidx.hilt:hilt-navigation-compose:${Versions.HILT_NAVIGATION_COMPOSE}" - const val COMPILER = "com.google.dagger:hilt-compiler:${Versions.HILT}" - - const val JAVAX_INJECT = "javax.inject:javax.inject:${Versions.JAVAX_INJECT}" - } - - object Kotlin { - const val COROUTINES_CORE = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.KOTLIN_COROUTINES}" - } - - object Log { - const val TIMBER = "com.jakewharton.timber:timber:${Versions.TIMBER}" - - const val CHUCKER = "com.github.chuckerteam.chucker:library:${Versions.CHUCKER}" - const val CHUCKER_NO_OP = "com.github.chuckerteam.chucker:library-no-op:${Versions.CHUCKER}" - } - - object Network { - const val RETROFIT = "com.squareup.retrofit2:retrofit:${Versions.RETROFIT}" - const val RETROFIT_CONVERTER_MOSHI = "com.squareup.retrofit2:converter-moshi:${Versions.RETROFIT}" - - const val OKHTTP = "com.squareup.okhttp3:okhttp:${Versions.OKHTTP}" - const val OKHTTP_LOGGING_INTERCEPTOR = "com.squareup.okhttp3:logging-interceptor:${Versions.OKHTTP}" - - const val MOSHI = "com.squareup.moshi:moshi:${Versions.MOSHI}" - const val MOSHI_ADAPTERS = "com.squareup.moshi:moshi-adapters:${Versions.MOSHI}" - const val MOSHI_KOTLIN = "com.squareup.moshi:moshi-kotlin:${Versions.MOSHI}" - } - - object Util { - const val COMMON_KTX = "com.github.nimblehq:android-common-ktx:${Versions.COMMON_KTX}" - } - - object Test { - const val COMPOSE_UI_TEST_JUNIT = "androidx.compose.ui:ui-test-junit4" - const val COROUTINES = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.KOTLIN_COROUTINES}" - - const val JUNIT = "junit:junit:${Versions.JUNIT}" - - const val KOTEST = "io.kotest:kotest-assertions-core:${Versions.KOTEST}" - const val MOCKK = "io.mockk:mockk:${Versions.MOCKK}" - - const val ROBOLECTRIC = "org.robolectric:robolectric:${Versions.ROBOLECTRIC}" - - const val TEST_CORE = "androidx.test:core:${Versions.CORE}" - const val TURBINE = "app.cash.turbine:turbine:${Versions.TURBINE}" - } -} diff --git a/template-compose/buildSrc/src/main/java/Plugins.kt b/template-compose/buildSrc/src/main/java/Plugins.kt deleted file mode 100644 index d22a2cf30..000000000 --- a/template-compose/buildSrc/src/main/java/Plugins.kt +++ /dev/null @@ -1,16 +0,0 @@ -object Plugins { - const val ANDROID_APPLICATION = "com.android.application" - const val ANDROID_LIBRARY = "com.android.library" - const val JAVA_LIBRARY = "java-library" - - const val DETEKT = "io.gitlab.arturbosch.detekt" - - const val HILT_ANDROID = "com.google.dagger.hilt.android" - - const val KOTLIN_JVM = "org.jetbrains.kotlin.jvm" - const val KOTLIN_ANDROID = "org.jetbrains.kotlin.android" - const val KOTLIN_KAPT = "kotlin-kapt" - const val KOTLIN_PARCELIZE = "kotlin-parcelize" - - const val KOVER = "org.jetbrains.kotlinx.kover" -} diff --git a/template-compose/buildSrc/src/main/java/Versions.kt b/template-compose/buildSrc/src/main/java/Versions.kt index 04e5458ab..d636de1f1 100644 --- a/template-compose/buildSrc/src/main/java/Versions.kt +++ b/template-compose/buildSrc/src/main/java/Versions.kt @@ -6,44 +6,5 @@ object Versions { const val ANDROID_VERSION_CODE = 1 const val ANDROID_VERSION_NAME = "1.0.0" - const val ACCOMPANIST = "0.30.1" - - const val CHUCKER = "3.5.2" - const val COMMON_KTX = "0.1.1" - const val COMPOSE_BOM = "2023.09.02" const val COMPOSE_COMPILER = "1.5.3" - const val COMPOSE_NAVIGATION = "2.5.3" - const val CORE = "1.4.0" - const val CORE_KTX = "1.10.1" - - const val DATASTORE_PREFERENCES = "1.0.0" - const val DETEKT = "1.21.0" - - const val GRADLE = "8.1.2" - - const val HILT = "2.48" - const val HILT_NAVIGATION_COMPOSE = "1.0.0" - - const val JAVAX_INJECT = "1" - const val JUNIT = "4.13.2" - - const val KOTEST = "5.6.2" - const val KOTLIN = "1.9.10" - const val KOTLIN_COROUTINES = "1.7.1" - const val KOVER = "0.7.3" - - const val LIFECYCLE = "2.6.1" - - const val MOCKK = "1.13.5" - const val MOSHI = "1.12.0" - - const val OKHTTP = "4.11.0" - - const val RETROFIT = "2.9.0" - const val ROBOLECTRIC = "4.10.2" - - const val SECURITY_CRYPTO = "1.0.0" - - const val TIMBER = "4.7.1" - const val TURBINE = "0.13.0" } diff --git a/template-compose/data/build.gradle.kts b/template-compose/data/build.gradle.kts index 417bc2178..fd7edea53 100644 --- a/template-compose/data/build.gradle.kts +++ b/template-compose/data/build.gradle.kts @@ -1,7 +1,7 @@ plugins { - id(Plugins.ANDROID_LIBRARY) - id(Plugins.KOTLIN_ANDROID) - id(Plugins.KOVER) + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kover) } android { @@ -46,35 +46,18 @@ android { dependencies { implementation(project(Modules.DOMAIN)) - with(Dependencies.AndroidX) { - implementation(CORE_KTX) - implementation(DATASTORE_PREFERENCES) - implementation(SECURITY_CRYPTO) - } - - with(Dependencies.Hilt) { - implementation(JAVAX_INJECT) - } + implementation(libs.androidx.core) + implementation(libs.androidx.datastorePreferences) + implementation(libs.androidx.securityCrypto) - with(Dependencies.Network) { - api(RETROFIT) - api(RETROFIT_CONVERTER_MOSHI) + implementation(libs.javax.inject) - api(OKHTTP) - api(OKHTTP_LOGGING_INTERCEPTOR) + api(libs.bundles.retrofit) + api(libs.bundles.okhttp) + api(libs.moshi) + implementation(libs.bundles.moshi) - api(MOSHI) - implementation(MOSHI_ADAPTERS) - implementation(MOSHI_KOTLIN) - } - - with(Dependencies.Test) { - testImplementation(COROUTINES) - testImplementation(JUNIT) - testImplementation(KOTEST) - testImplementation(MOCKK) - testImplementation(ROBOLECTRIC) - testImplementation(TEST_CORE) - testImplementation(TURBINE) - } + testImplementation(libs.bundles.unitTest) + testImplementation(libs.test.turbine) + testImplementation(libs.test.robolectric) } diff --git a/template-compose/domain/build.gradle.kts b/template-compose/domain/build.gradle.kts index 723baa6fb..5a65d7e2b 100644 --- a/template-compose/domain/build.gradle.kts +++ b/template-compose/domain/build.gradle.kts @@ -1,7 +1,7 @@ plugins { - id(Plugins.JAVA_LIBRARY) - id(Plugins.KOTLIN_JVM) - id(Plugins.KOVER) + id(libs.plugins.javaLibrary.get().pluginId) + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kover) } java { @@ -10,18 +10,8 @@ java { } dependencies { - with(Dependencies.Kotlin) { - implementation(COROUTINES_CORE) - } + implementation(libs.kotlin.coroutines.core) + implementation(libs.javax.inject) - with(Dependencies.Hilt) { - implementation(JAVAX_INJECT) - } - - with(Dependencies.Test) { - testImplementation(COROUTINES) - testImplementation(JUNIT) - testImplementation(KOTEST) - testImplementation(MOCKK) - } + testImplementation(libs.bundles.unitTest) } diff --git a/template-compose/gradle/libs.versions.toml b/template-compose/gradle/libs.versions.toml new file mode 100644 index 000000000..e1b231388 --- /dev/null +++ b/template-compose/gradle/libs.versions.toml @@ -0,0 +1,141 @@ +[versions] +accompanist = "0.30.1" +chucker = "3.5.2" +composeBom = "2023.09.02" +composeNavigation = "2.5.3" +core = "1.10.1" +datastore = "1.0.0" +detekt = "1.21.0" +gradle = "8.1.2" +hilt = "2.48" +hiltNavigation = "1.0.0" +javaxInject = "1" +kotlinCoroutines = "1.7.1" +nimbleCommon = "0.1.1" +lifecycle = "2.6.1" +security = "1.0.0" +junit = "4.13.2" +kotest = "5.6.2" +kotlin = "1.9.10" +kover = "0.7.3" +mockk = "1.13.5" +moshi = "1.12.0" +okhttp = "4.11.0" +retrofit = "2.9.0" +robolectric = "4.10.2" +timber = "4.7.1" +turbine = "0.13.0" + +[libraries] +# AndroidX +androidx-core = { group = "androidx.core", name = "core-ktx", version.ref = "core" } +androidx-lifecycle-runtime = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycle" } +androidx-lifecycle-compose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "lifecycle" } +androidx-datastorePreferences = { group = "androidx.datastore", name = "datastore-preferences", version.ref = "datastore" } +androidx-securityCrypto = { group = "androidx.security", name = "security-crypto", version.ref = "security" } + +# Compose +compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" } +compose-ui = { group = "androidx.compose.ui", name = "ui" } +compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" } +compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" } +compose-material = { group = "androidx.compose.material", name = "material" } +compose-navigation = { group = "androidx.navigation", name = "navigation-compose", version.ref = "composeNavigation" } +accompanist-permissions = { group = "com.google.accompanist", name = "accompanist-permissions", version.ref = "accompanist" } + +# Hilt +hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" } +hilt-navigation = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "hiltNavigation" } +hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler", version.ref = "hilt" } +javax-inject = { group = "javax.inject", name = "javax.inject", version.ref = "javaxInject" } + +# Kotlin +kotlin-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinCoroutines" } + +# Log +timber = { group = "com.jakewharton.timber", name = "timber", version.ref = "timber" } +chucker = { group = "com.github.chuckerteam.chucker", name = "library", version.ref = "chucker" } +chucker-no-op = { group = "com.github.chuckerteam.chucker", name = "library-no-op", version.ref = "chucker" } + +# Network +moshi = { group = "com.squareup.moshi", name = "moshi", version.ref = "moshi" } +moshi-adapters = { group = "com.squareup.moshi", name = "moshi-adapters", version.ref = "moshi" } +moshi-kotlin = { group = "com.squareup.moshi", name = "moshi-kotlin", version.ref = "moshi" } +okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" } +okhttp-logging = { group = "com.squareup.okhttp3", name = "logging-interceptor", version.ref = "okhttp" } +retrofit = { group = "com.squareup.retrofit2", name = "retrofit", version.ref = "retrofit" } +retrofit-moshi = { group = "com.squareup.retrofit2", name = "converter-moshi", version.ref = "retrofit" } + +# Util +nimble-common = { group = "com.github.nimblehq", name = "android-common-ktx", version.ref = "nimbleCommon" } + +# Test +test-junit = { group = "junit", name = "junit", version.ref = "junit" } +test-kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "kotlinCoroutines" } +test-kotest-assertions-core = { group = "io.kotest", name = "kotest-assertions-core", version.ref = "kotest" } +test-mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" } +test-turbine = { group = "app.cash.turbine", name = "turbine", version.ref = "turbine" } + +test-compose-ui = { group = "androidx.compose.ui", name = "ui-test-junit4" } +test-robolectric = { group = "org.robolectric", name = "robolectric", version.ref = "robolectric" } + +[bundles] + +androidx = [ + "androidx-core", + "androidx-lifecycle-runtime", + "androidx-lifecycle-compose", + "androidx-datastorePreferences", +] + +compose = [ + "compose-ui", + "compose-ui-tooling-preview", + "compose-material", + "compose-navigation", + "accompanist-permissions", +] + +hilt = [ + "hilt-android", + "hilt-navigation", +] + +retrofit = [ + "retrofit", + "retrofit-moshi", +] + +okhttp = [ + "okhttp", + "okhttp-logging", +] + +moshi = [ + "moshi-adapters", + "moshi-kotlin", +] + +unitTest = [ + "test-kotlinx-coroutines-test", + "test-junit", + "test-kotest-assertions-core", + "test-mockk", +] + +implementationTest = [ + "test-compose-ui", + "test-robolectric", +] + +[plugins] +android-application = { id = "com.android.application", version.ref = "gradle" } +android-library = { id = "com.android.library", version.ref = "gradle" } +detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } +hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" } +javaLibrary = { id = "java-library" } +kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" } +kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" } +kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }