From d57e3b7ec9a3a67c1d14c0405b2c92b80d870e4a Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 24 Sep 2024 12:26:48 +0200 Subject: [PATCH 1/3] Introduce ModulesConfig for easier configurations of modules. --- plugins/src/main/kotlin/ModulesConfig.kt | 15 +++++++++++ .../src/main/kotlin/config/AnalyticsConfig.kt | 23 ++++++++++++++++ .../kotlin/extension/DependencyHandleScope.kt | 26 ++++++++++++------- 3 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 plugins/src/main/kotlin/ModulesConfig.kt create mode 100644 plugins/src/main/kotlin/config/AnalyticsConfig.kt diff --git a/plugins/src/main/kotlin/ModulesConfig.kt b/plugins/src/main/kotlin/ModulesConfig.kt new file mode 100644 index 0000000000..649c948e26 --- /dev/null +++ b/plugins/src/main/kotlin/ModulesConfig.kt @@ -0,0 +1,15 @@ +/* + * Copyright 2024 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only + * Please see LICENSE in the repository root for full details. + */ + +import config.AnalyticsConfig + +object ModulesConfig { + val analyticsConfig: AnalyticsConfig = AnalyticsConfig.Enabled( + withPosthog = true, + withSentry = true + ) +} diff --git a/plugins/src/main/kotlin/config/AnalyticsConfig.kt b/plugins/src/main/kotlin/config/AnalyticsConfig.kt new file mode 100644 index 0000000000..5bc92da723 --- /dev/null +++ b/plugins/src/main/kotlin/config/AnalyticsConfig.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2024 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only + * Please see LICENSE in the repository root for full details. + */ + +package config + +sealed interface AnalyticsConfig { + data class Enabled( + val withPosthog: Boolean, + val withSentry: Boolean, + ) : AnalyticsConfig { + init { + require(withPosthog || withSentry) { + "At least one analytics provider must be enabled" + } + } + } + + object Disabled : AnalyticsConfig +} diff --git a/plugins/src/main/kotlin/extension/DependencyHandleScope.kt b/plugins/src/main/kotlin/extension/DependencyHandleScope.kt index 5a8df0694d..fef1ea147a 100644 --- a/plugins/src/main/kotlin/extension/DependencyHandleScope.kt +++ b/plugins/src/main/kotlin/extension/DependencyHandleScope.kt @@ -7,14 +7,14 @@ package extension +import config.AnalyticsConfig +import ModulesConfig import org.gradle.accessors.dm.LibrariesForLibs import org.gradle.api.Action import org.gradle.api.artifacts.ExternalModuleDependency import org.gradle.api.logging.Logger -import org.gradle.api.provider.Provider import org.gradle.kotlin.dsl.DependencyHandlerScope import org.gradle.kotlin.dsl.closureOf -import org.gradle.kotlin.dsl.exclude import org.gradle.kotlin.dsl.project import java.io.File @@ -24,7 +24,7 @@ private fun DependencyHandlerScope.implementation(dependency: Any) = dependencie private fun DependencyHandlerScope.implementation( dependency: Any, config: Action -) = dependencies.add("implementation", dependency, closureOf { config.execute(this) }) +) = dependencies.add("implementation", dependency, closureOf { config.execute(this) }) private fun DependencyHandlerScope.androidTestImplementation(dependency: Any) = dependencies.add("androidTestImplementation", dependency) @@ -111,13 +111,21 @@ fun DependencyHandlerScope.allLibrariesImpl() { } fun DependencyHandlerScope.allServicesImpl() { - // For analytics configuration, either use noop, or use the impl, with at least one analyticsproviders implementation - // implementation(project(":services:analytics:noop")) - implementation(project(":services:analytics:impl")) implementation(project(":services:analytics:compose")) - implementation(project(":services:analyticsproviders:posthog")) - implementation(project(":services:analyticsproviders:sentry")) - + when (ModulesConfig.analyticsConfig) { + AnalyticsConfig.Disabled -> { + implementation(project(":services:analytics:noop")) + } + is AnalyticsConfig.Enabled -> { + implementation(project(":services:analytics:impl")) + if (ModulesConfig.analyticsConfig.withPosthog) { + implementation(project(":services:analyticsproviders:posthog")) + } + if (ModulesConfig.analyticsConfig.withSentry) { + implementation(project(":services:analyticsproviders:sentry")) + } + } + } implementation(project(":services:apperror:impl")) implementation(project(":services:appnavstate:impl")) implementation(project(":services:toolbox:impl")) From 1a979cd14208405412e529b08a8d338a2c462d73 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 24 Sep 2024 12:31:18 +0200 Subject: [PATCH 2/3] Use ModulesConfig for push provider modules. --- app/build.gradle.kts | 10 ++++++---- plugins/src/main/kotlin/ModulesConfig.kt | 8 +++++++- .../main/kotlin/config/PushProvidersConfig.kt | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 plugins/src/main/kotlin/config/PushProvidersConfig.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 7f814a814a..1cc4de2eeb 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -250,10 +250,12 @@ dependencies { implementation(projects.libraries.uiStrings) anvil(projects.anvilcodegen) - // Comment to not include firebase in the project - "gplayImplementation"(projects.libraries.pushproviders.firebase) - // Comment to not include unified push in the project - implementation(projects.libraries.pushproviders.unifiedpush) + if (ModulesConfig.pushProvidersConfig.includeFirebase) { + "gplayImplementation"(projects.libraries.pushproviders.firebase) + } + if (ModulesConfig.pushProvidersConfig.includeFirebase) { + implementation(projects.libraries.pushproviders.unifiedpush) + } implementation(libs.appyx.core) implementation(libs.androidx.splash) diff --git a/plugins/src/main/kotlin/ModulesConfig.kt b/plugins/src/main/kotlin/ModulesConfig.kt index 649c948e26..f24d4f56b4 100644 --- a/plugins/src/main/kotlin/ModulesConfig.kt +++ b/plugins/src/main/kotlin/ModulesConfig.kt @@ -6,10 +6,16 @@ */ import config.AnalyticsConfig +import config.PushProvidersConfig object ModulesConfig { + val pushProvidersConfig = PushProvidersConfig( + includeFirebase = true, + includeUnifiedPush = true, + ) + val analyticsConfig: AnalyticsConfig = AnalyticsConfig.Enabled( withPosthog = true, - withSentry = true + withSentry = true, ) } diff --git a/plugins/src/main/kotlin/config/PushProvidersConfig.kt b/plugins/src/main/kotlin/config/PushProvidersConfig.kt new file mode 100644 index 0000000000..1e7e43b1ae --- /dev/null +++ b/plugins/src/main/kotlin/config/PushProvidersConfig.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2024 New Vector Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only + * Please see LICENSE in the repository root for full details. + */ + +package config + +data class PushProvidersConfig( + val includeFirebase: Boolean, + val includeUnifiedPush: Boolean, +) { + init { + require(includeFirebase || includeUnifiedPush) { + "At least one push provider must be included" + } + } +} From 4fc187896a32b7969c095d8656b8cf1b320a0249 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 24 Sep 2024 13:40:29 +0200 Subject: [PATCH 3/3] Fix copy paste error --- app/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1cc4de2eeb..c2c38ae219 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -253,7 +253,7 @@ dependencies { if (ModulesConfig.pushProvidersConfig.includeFirebase) { "gplayImplementation"(projects.libraries.pushproviders.firebase) } - if (ModulesConfig.pushProvidersConfig.includeFirebase) { + if (ModulesConfig.pushProvidersConfig.includeUnifiedPush) { implementation(projects.libraries.pushproviders.unifiedpush) }