From aedc3447037ebdc639f2aa2db18f1bf947cd1e19 Mon Sep 17 00:00:00 2001 From: Paul Rybitskyi Date: Thu, 22 Aug 2024 01:23:37 +0300 Subject: [PATCH] Create dependency bundles for testing libs (#227) --- app/build.gradle.kts | 4 ---- .../extensions/DependencyHandlerExtensions.kt | 10 ++++++++++ .../gamedge/plugins/GamedgeAndroidPlugin.kt | 9 ++++++--- .../gamedge/plugins/GamedgeFeaturePlugin.kt | 11 ++--------- .../gamedge/plugins/GamedgeRemoteApiPlugin.kt | 14 ++++---------- common-api/build.gradle.kts | 3 --- common-data/build.gradle.kts | 13 +------------ common-domain/build.gradle.kts | 6 +----- common-ui-widgets/build.gradle.kts | 3 --- common-ui/build.gradle.kts | 3 --- core/build.gradle.kts | 11 +---------- database/build.gradle.kts | 13 ++----------- gradle/libs.versions.toml | 18 ++++++++++++++++++ 13 files changed, 45 insertions(+), 73 deletions(-) create mode 100644 buildSrc/src/main/java/com/paulrybitskyi/gamedge/extensions/DependencyHandlerExtensions.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ee7c68aa6..298a2a874 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -46,10 +46,6 @@ dependencies { implementation(libs.commonsCore) implementation(libs.commonsKtx) - - testImplementation(libs.jUnit) - - androidTestImplementation(libs.jUnitExt) } val installGitHook by tasks.registering(Copy::class) { diff --git a/buildSrc/src/main/java/com/paulrybitskyi/gamedge/extensions/DependencyHandlerExtensions.kt b/buildSrc/src/main/java/com/paulrybitskyi/gamedge/extensions/DependencyHandlerExtensions.kt new file mode 100644 index 000000000..def5c4d6d --- /dev/null +++ b/buildSrc/src/main/java/com/paulrybitskyi/gamedge/extensions/DependencyHandlerExtensions.kt @@ -0,0 +1,10 @@ +package com.paulrybitskyi.gamedge.extensions + +import org.gradle.api.artifacts.ExternalModuleDependencyBundle +import org.gradle.api.artifacts.dsl.DependencyHandler + +fun DependencyHandler.addBundle(configurationName: String, bundle: ExternalModuleDependencyBundle) { + bundle.forEach { dependency -> + add(configurationName, dependency) + } +} diff --git a/buildSrc/src/main/java/com/paulrybitskyi/gamedge/plugins/GamedgeAndroidPlugin.kt b/buildSrc/src/main/java/com/paulrybitskyi/gamedge/plugins/GamedgeAndroidPlugin.kt index 3a971c6ee..1a4ffea5c 100644 --- a/buildSrc/src/main/java/com/paulrybitskyi/gamedge/plugins/GamedgeAndroidPlugin.kt +++ b/buildSrc/src/main/java/com/paulrybitskyi/gamedge/plugins/GamedgeAndroidPlugin.kt @@ -151,8 +151,11 @@ class GamedgeAndroidPlugin : Plugin { return (get(key) as T) } - private fun Project.addDependencies() { - dependencies.add("coreLibraryDesugaring", libs.desugaredJdk.get()) - dependencies.add("androidTestImplementation", project(localModules.commonTesting)) + private fun Project.addDependencies(): Unit = with(dependencies) { + add("implementation", libs.coroutines.get()) + add("implementation", libs.kotlinResult.get()) + + add("coreLibraryDesugaring", libs.desugaredJdk.get()) + add("androidTestImplementation", project(localModules.commonTesting)) } } diff --git a/buildSrc/src/main/java/com/paulrybitskyi/gamedge/plugins/GamedgeFeaturePlugin.kt b/buildSrc/src/main/java/com/paulrybitskyi/gamedge/plugins/GamedgeFeaturePlugin.kt index ed7eddda3..a5df7a9c2 100644 --- a/buildSrc/src/main/java/com/paulrybitskyi/gamedge/plugins/GamedgeFeaturePlugin.kt +++ b/buildSrc/src/main/java/com/paulrybitskyi/gamedge/plugins/GamedgeFeaturePlugin.kt @@ -1,5 +1,6 @@ package com.paulrybitskyi.gamedge.plugins +import com.paulrybitskyi.gamedge.extensions.addBundle import com.paulrybitskyi.gamedge.extensions.libs import org.gradle.api.Plugin import org.gradle.api.Project @@ -24,19 +25,11 @@ class GamedgeFeaturePlugin : Plugin { add("implementation", project(localModules.core)) add("implementation", project(localModules.commonUi)) add("implementation", project(localModules.commonUiWidgets)) - add("implementation", libs.coroutines.get()) add("implementation", libs.composeHilt.get()) add("implementation", libs.commonsCore.get()) add("implementation", libs.commonsKtx.get()) - add("implementation", libs.kotlinResult.get()) add("implementation", libs.coil.get()) add("testImplementation", project(localModules.commonTesting)) - add("testImplementation", libs.jUnit.get()) - add("testImplementation", libs.truth.get()) - add("testImplementation", libs.mockk.get()) - add("testImplementation", libs.coroutinesTesting.get()) - add("testImplementation", libs.turbine.get()) - add("androidTestImplementation", libs.testRunner.get()) - add("androidTestImplementation", libs.jUnitExt.get()) + addBundle("testImplementation", libs.bundles.testing.get()) } } diff --git a/buildSrc/src/main/java/com/paulrybitskyi/gamedge/plugins/GamedgeRemoteApiPlugin.kt b/buildSrc/src/main/java/com/paulrybitskyi/gamedge/plugins/GamedgeRemoteApiPlugin.kt index 1042bc6ca..a22db923f 100644 --- a/buildSrc/src/main/java/com/paulrybitskyi/gamedge/plugins/GamedgeRemoteApiPlugin.kt +++ b/buildSrc/src/main/java/com/paulrybitskyi/gamedge/plugins/GamedgeRemoteApiPlugin.kt @@ -1,6 +1,7 @@ package com.paulrybitskyi.gamedge.plugins import com.android.build.api.dsl.LibraryExtension +import com.paulrybitskyi.gamedge.extensions.addBundle import com.paulrybitskyi.gamedge.extensions.libs import org.gradle.api.Plugin import org.gradle.api.Project @@ -33,20 +34,13 @@ class GamedgeRemoteApiPlugin : Plugin { add("api", project(localModules.commonApi)) add("implementation", project(localModules.core)) - add("implementation", libs.coroutines.get()) add("implementation", libs.kotlinxSerialization.get()) add("implementation", libs.retrofit.get()) - add("implementation", libs.kotlinResult.get()) add("testImplementation", project(localModules.commonTesting)) - add("testImplementation", libs.jUnit.get()) - add("testImplementation", libs.truth.get()) - add("testImplementation", libs.mockk.get()) - add("testImplementation", libs.coroutinesTesting.get()) - - add("androidTestImplementation", libs.testRunner.get()) - add("androidTestImplementation", libs.jUnitExt.get()) - add("androidTestImplementation", libs.truth.get()) + addBundle("testImplementation", libs.bundles.testing.get()) + + addBundle("androidTestImplementation", libs.bundles.testingAndroid.get()) add("androidTestImplementation", libs.mockWebServer.get()) } } diff --git a/common-api/build.gradle.kts b/common-api/build.gradle.kts index f94a9209c..450dfab4a 100644 --- a/common-api/build.gradle.kts +++ b/common-api/build.gradle.kts @@ -38,7 +38,4 @@ dependencies { implementation(libs.retrofitKotlinxSerializationConverter) implementation(libs.kotlinResult) - - testImplementation(libs.jUnit) - androidTestImplementation(libs.jUnitExt) } diff --git a/common-data/build.gradle.kts b/common-data/build.gradle.kts index 19290633a..dc87d9890 100644 --- a/common-data/build.gradle.kts +++ b/common-data/build.gradle.kts @@ -31,20 +31,9 @@ dependencies { implementation(project(localModules.igdbApi)) implementation(project(localModules.database)) - implementation(libs.coroutines) - implementation(libs.prefsDataStore) implementation(libs.protoDataStore) - implementation(libs.kotlinResult) - testImplementation(project(localModules.commonTesting)) - testImplementation(libs.jUnit) - testImplementation(libs.truth) - testImplementation(libs.mockk) - testImplementation(libs.coroutinesTesting) - testImplementation(libs.turbine) - - androidTestImplementation(libs.testRunner) - androidTestImplementation(libs.jUnitExt) + testImplementation(libs.bundles.testing) } diff --git a/common-domain/build.gradle.kts b/common-domain/build.gradle.kts index da2842609..e55f6e62f 100644 --- a/common-domain/build.gradle.kts +++ b/common-domain/build.gradle.kts @@ -27,9 +27,5 @@ dependencies { kapt(libs.daggerHiltCoreCompiler) testImplementation(project(localModules.commonTestingDomain)) - testImplementation(libs.jUnit) - testImplementation(libs.truth) - testImplementation(libs.mockk) - testImplementation(libs.coroutinesTesting) - testImplementation(libs.turbine) + testImplementation(libs.bundles.testing) } diff --git a/common-ui-widgets/build.gradle.kts b/common-ui-widgets/build.gradle.kts index f2c843e97..d5807253f 100644 --- a/common-ui-widgets/build.gradle.kts +++ b/common-ui-widgets/build.gradle.kts @@ -31,7 +31,4 @@ dependencies { implementation(project(localModules.commonUi)) implementation(libs.coil) - - testImplementation(libs.jUnit) - androidTestImplementation(libs.jUnitExt) } diff --git a/common-ui/build.gradle.kts b/common-ui/build.gradle.kts index c00ef9a5b..5e67c38c4 100644 --- a/common-ui/build.gradle.kts +++ b/common-ui/build.gradle.kts @@ -32,7 +32,4 @@ dependencies { implementation(libs.commonsKtx) implementation(libs.coil) - - testImplementation(libs.jUnit) - androidTestImplementation(libs.jUnitExt) } diff --git a/core/build.gradle.kts b/core/build.gradle.kts index fa7be829c..e5fd74045 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -27,7 +27,6 @@ android { dependencies { implementation(project(localModules.commonDomain)) - implementation(libs.coroutines) implementation(libs.kotlinxSerialization) implementation(libs.browser) @@ -37,14 +36,6 @@ dependencies { implementation(libs.commonsNetwork) implementation(libs.commonsWindowAnims) - implementation(libs.kotlinResult) - testImplementation(project(localModules.commonTesting)) - testImplementation(libs.jUnit) - testImplementation(libs.truth) - testImplementation(libs.mockk) - testImplementation(libs.coroutinesTesting) - - androidTestImplementation(libs.testRunner) - androidTestImplementation(libs.jUnitExt) + testImplementation(libs.bundles.testing) } diff --git a/database/build.gradle.kts b/database/build.gradle.kts index 37331d3ac..f35fbd2f6 100644 --- a/database/build.gradle.kts +++ b/database/build.gradle.kts @@ -45,7 +45,6 @@ ksp { dependencies { implementation(project(localModules.core)) - implementation(libs.coroutines) implementation(libs.kotlinxSerialization) implementation(libs.room) @@ -53,17 +52,9 @@ dependencies { ksp(libs.roomCompiler) testImplementation(project(localModules.commonTesting)) - testImplementation(libs.jUnit) - testImplementation(libs.truth) - testImplementation(libs.mockk) - testImplementation(libs.coroutinesTesting) - testImplementation(libs.turbine) + testImplementation(libs.bundles.testing) - androidTestImplementation(libs.testRunner) - androidTestImplementation(libs.jUnitExt) - androidTestImplementation(libs.truth) + androidTestImplementation(libs.bundles.testingAndroid) androidTestImplementation(libs.archCore) - androidTestImplementation(libs.coroutinesTesting) - androidTestImplementation(libs.turbine) androidTestImplementation(libs.roomTesting) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 72b63566d..ab35073d4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -169,3 +169,21 @@ archCore = { module = "androidx.arch.core:core-testing", version.ref = "archCore daggerHiltTesting = { module = "com.google.dagger:hilt-android-testing", version.ref = "daggerHilt" } roomTesting = { module = "androidx.room:room-testing", version.ref = "room" } mockWebServer = { module = "com.squareup.okhttp3:mockwebserver", version.ref = "mockWebServer" } + +[bundles] +testing = [ + "jUnit", + "truth", + "mockk", + "coroutinesTesting", + "turbine", +] + +testingAndroid = [ + "testRunner", + "jUnit", + "jUnitExt", + "truth", + "coroutinesTesting", + "turbine", +]