Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ModulesConfig #3530

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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.includeUnifiedPush) {
implementation(projects.libraries.pushproviders.unifiedpush)
}

implementation(libs.appyx.core)
implementation(libs.androidx.splash)
Expand Down
21 changes: 21 additions & 0 deletions plugins/src/main/kotlin/ModulesConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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
import config.PushProvidersConfig

object ModulesConfig {
val pushProvidersConfig = PushProvidersConfig(
includeFirebase = true,
includeUnifiedPush = true,
)

val analyticsConfig: AnalyticsConfig = AnalyticsConfig.Enabled(
withPosthog = true,
withSentry = true,
)
}
23 changes: 23 additions & 0 deletions plugins/src/main/kotlin/config/AnalyticsConfig.kt
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 19 additions & 0 deletions plugins/src/main/kotlin/config/PushProvidersConfig.kt
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
26 changes: 17 additions & 9 deletions plugins/src/main/kotlin/extension/DependencyHandleScope.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,7 +24,7 @@ private fun DependencyHandlerScope.implementation(dependency: Any) = dependencie
private fun DependencyHandlerScope.implementation(
dependency: Any,
config: Action<ExternalModuleDependency>
) = dependencies.add("implementation", dependency, closureOf<ExternalModuleDependency> { config.execute(this) })
) = dependencies.add("implementation", dependency, closureOf<ExternalModuleDependency> { config.execute(this) })

private fun DependencyHandlerScope.androidTestImplementation(dependency: Any) = dependencies.add("androidTestImplementation", dependency)

Expand Down Expand Up @@ -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"))
Expand Down
Loading