From 07d0f1089f5fd080055f9e44cbe3e7283a61653e Mon Sep 17 00:00:00 2001 From: prudhvir3ddy Date: Thu, 10 Jul 2025 17:42:23 +0530 Subject: [PATCH] Refactor: Use Gradle version catalog This commit introduces the Gradle version catalog (`libs.versions.toml`) to manage dependencies and plugin versions centrally. Key changes: - Added `gradle/libs.versions.toml` defining versions, libraries, plugins, and bundles. - Updated `app/build.gradle.kts` to reference dependencies and plugins from the version catalog. - Updated project-level `build.gradle.kts` to use plugin aliases from the version catalog. --- app/build.gradle.kts | 65 ++++++++---------- build.gradle.kts | 6 +- gradle/libs.versions.toml | 137 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+), 40 deletions(-) create mode 100644 gradle/libs.versions.toml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9d1e7199..8aad3797 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,17 +1,17 @@ plugins { - id("com.android.application") - id("org.jetbrains.kotlin.android") - id("kotlin-parcelize") + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.parcelize) } android { namespace = "com.bitchat.android" - compileSdk = 34 + compileSdk = libs.versions.compileSdk.get().toInt() defaultConfig { applicationId = "com.bitchat.android" - minSdk = 26 // API 26 for proper BLE support - targetSdk = 34 + minSdk = libs.versions.minSdk.get().toInt() + targetSdk = libs.versions.targetSdk.get().toInt() versionCode = 1 versionName = "1.0" @@ -41,7 +41,7 @@ android { compose = true } composeOptions { - kotlinCompilerExtensionVersion = "1.5.5" + kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get() } packaging { resources { @@ -56,54 +56,45 @@ android { } dependencies { - implementation("androidx.core:core-ktx:1.12.0") - implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0") - implementation("androidx.activity:activity-compose:1.8.2") - implementation(platform("androidx.compose:compose-bom:2023.10.01")) - implementation("androidx.compose.ui:ui") - implementation("androidx.compose.ui:ui-graphics") - implementation("androidx.compose.ui:ui-tooling-preview") - implementation("androidx.compose.material3:material3") + // Core Android dependencies + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.activity.compose) + implementation(libs.androidx.appcompat) - // AppCompat for theme support - implementation("androidx.appcompat:appcompat:1.6.1") + // Compose + implementation(platform(libs.androidx.compose.bom)) + implementation(libs.bundles.compose) - // ViewModel and LiveData - implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0") - implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.7.0") - implementation("androidx.compose.runtime:runtime-livedata") + // Lifecycle + implementation(libs.bundles.lifecycle) // Navigation - implementation("androidx.navigation:navigation-compose:2.7.6") + implementation(libs.androidx.navigation.compose) // Permissions - implementation("com.google.accompanist:accompanist-permissions:0.32.0") + implementation(libs.accompanist.permissions) // Cryptography - implementation("org.bouncycastle:bcprov-jdk15on:1.70") - implementation("com.google.crypto.tink:tink-android:1.10.0") + implementation(libs.bundles.cryptography) // JSON - implementation("com.google.code.gson:gson:2.10.1") + implementation(libs.gson) // Coroutines - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3") + implementation(libs.kotlinx.coroutines.android) // Bluetooth - implementation("no.nordicsemi.android:ble:2.6.1") + implementation(libs.nordic.ble) // Compression - implementation("org.lz4:lz4-java:1.8.0") + implementation(libs.lz4.java) // Security preferences - implementation("androidx.security:security-crypto:1.1.0-alpha06") + implementation(libs.androidx.security.crypto) // Testing - testImplementation("junit:junit:4.13.2") - androidTestImplementation("androidx.test.ext:junit:1.1.5") - androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") - androidTestImplementation(platform("androidx.compose:compose-bom:2023.10.01")) - androidTestImplementation("androidx.compose.ui:ui-test-junit4") - debugImplementation("androidx.compose.ui:ui-tooling") - debugImplementation("androidx.compose.ui:ui-test-manifest") + testImplementation(libs.bundles.testing) + androidTestImplementation(platform(libs.androidx.compose.bom)) + androidTestImplementation(libs.bundles.compose.testing) + debugImplementation(libs.androidx.compose.ui.tooling) } diff --git a/build.gradle.kts b/build.gradle.kts index 7ffa57fe..38d6e783 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,6 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id("com.android.application") version "8.2.0" apply false - id("org.jetbrains.kotlin.android") version "1.9.20" apply false - id("com.android.library") version "8.2.0" apply false + alias(libs.plugins.android.application) apply false + alias(libs.plugins.kotlin.android) apply false + alias(libs.plugins.android.library) apply false } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 00000000..9d5cde54 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,137 @@ +[versions] +# Android and Kotlin +agp = "8.2.0" +kotlin = "1.9.20" +compileSdk = "34" +minSdk = "26" # API 26 for proper BLE support +targetSdk = "34" + +# AndroidX Core +core-ktx = "1.12.0" +lifecycle-runtime = "2.7.0" +activity-compose = "1.8.2" +appcompat = "1.6.1" + +# Compose +compose-bom = "2023.10.01" +compose-compiler = "1.5.5" + +# Navigation +navigation-compose = "2.7.6" + +# Accompanist +accompanist-permissions = "0.32.0" + +# Cryptography +bouncycastle = "1.70" +tink-android = "1.10.0" + +# JSON +gson = "2.10.1" + +# Coroutines +kotlinx-coroutines = "1.7.3" + +# Bluetooth +nordic-ble = "2.6.1" + +# Compression +lz4-java = "1.8.0" + +# Security +security-crypto = "1.1.0-alpha06" + +# Testing +junit = "4.13.2" +androidx-test-ext = "1.1.5" +espresso = "3.5.1" + +[libraries] +# AndroidX Core +androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" } +androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycle-runtime" } +androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activity-compose" } +androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } + +# Compose +androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "compose-bom" } +androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" } +androidx-compose-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" } +androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" } +androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" } +androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" } +androidx-compose-runtime = { group = "androidx.compose.runtime", name = "runtime" } +androidx-compose-runtime-livedata = { group = "androidx.compose.runtime", name = "runtime-livedata" } + +# Lifecycle +androidx-lifecycle-viewmodel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "lifecycle-runtime" } +androidx-lifecycle-livedata-ktx = { group = "androidx.lifecycle", name = "lifecycle-livedata-ktx", version.ref = "lifecycle-runtime" } + +# Navigation +androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigation-compose" } + +# Accompanist +accompanist-permissions = { group = "com.google.accompanist", name = "accompanist-permissions", version.ref = "accompanist-permissions" } + +# Cryptography +bouncycastle-bcprov = { group = "org.bouncycastle", name = "bcprov-jdk15on", version.ref = "bouncycastle" } +google-tink-android = { group = "com.google.crypto.tink", name = "tink-android", version.ref = "tink-android" } + +# JSON +gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" } + +# Coroutines +kotlinx-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "kotlinx-coroutines" } + +# Bluetooth +nordic-ble = { group = "no.nordicsemi.android", name = "ble", version.ref = "nordic-ble" } + +# Compression +lz4-java = { group = "org.lz4", name = "lz4-java", version.ref = "lz4-java" } + +# Security +androidx-security-crypto = { group = "androidx.security", name = "security-crypto", version.ref = "security-crypto" } + +# Testing +junit = { group = "junit", name = "junit", version.ref = "junit" } +androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-ext" } +androidx-test-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espresso" } +androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" } +androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" } + +[plugins] +android-application = { id = "com.android.application", version.ref = "agp" } +android-library = { id = "com.android.library", version.ref = "agp" } +kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +kotlin-parcelize = { id = "kotlin-parcelize" } + +[bundles] +compose = [ + "androidx-compose-ui", + "androidx-compose-ui-graphics", + "androidx-compose-ui-tooling-preview", + "androidx-compose-material3", + "androidx-compose-runtime-livedata" +] + +lifecycle = [ + "androidx-lifecycle-runtime-ktx", + "androidx-lifecycle-viewmodel-compose", + "androidx-lifecycle-livedata-ktx" +] + +cryptography = [ + "bouncycastle-bcprov", + "google-tink-android" +] + +testing = [ + "junit", + "androidx-test-ext-junit", + "androidx-test-espresso-core" +] + +compose-testing = [ + "androidx-compose-ui-test-junit4", + "androidx-compose-ui-test-manifest" +] \ No newline at end of file