From 61b09fe8f158f49ce01837381fcfbb8fdbe2bc4b Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Thu, 26 Sep 2024 10:21:22 +0200 Subject: [PATCH] [PM-7587] Support conditionally loading local sdk (#3957) --- README.md | 1 + app/build.gradle.kts | 23 ++++++++++++++++++++++- settings.gradle.kts | 3 +++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5941e5ae6..a9a8ad60c 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ 2. Create a `user.properties` file in the root directory of the project and add the following properties: - `gitHubToken`: A "classic" Github Personal Access Token (PAT) with the `read:packages` scope (ex: `gitHubToken=gph_xx...xx`). These can be generated by going to the [Github tokens page](https://github.com/settings/tokens). See [the Github Packages user documentation concerning authentication](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry#authenticating-to-github-packages) for more details. + - `localSdk`: A boolean value to determine if the SDK should be loaded from the local maven artifactory (ex: `localSdk=true`). This is particularly useful when developing new SDK capabilities. Review [Linking SDK to clients](https://contributing-docs.pages.dev/getting-started/sdk/#linking-sdk-to-clients) for more details. 3. Setup the code style formatter: diff --git a/app/build.gradle.kts b/app/build.gradle.kts index dcd98e3ab..6fd3ce718 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -2,6 +2,8 @@ import com.google.firebase.crashlytics.buildtools.gradle.tasks.InjectMappingFile import com.google.firebase.crashlytics.buildtools.gradle.tasks.UploadMappingFileTask import com.google.gms.googleservices.GoogleServicesTask import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import java.io.FileInputStream +import java.util.Properties plugins { alias(libs.plugins.android.application) @@ -20,6 +22,16 @@ plugins { alias(libs.plugins.sonarqube) } +/** + * Loads local user-specific build properties that are not checked into source control. + */ +val userProperties = Properties().apply { + val buildPropertiesFile = File(rootDir, "user.properties") + if (buildPropertiesFile.exists()) { + FileInputStream(buildPropertiesFile).use { load(it) } + } +} + android { namespace = "com.x8bit.bitwarden" compileSdk = libs.versions.compileSdk.get().toInt() @@ -130,6 +142,15 @@ kotlin { } } +configurations.all { + resolutionStrategy.dependencySubstitution { + if ((userProperties["localSdk"] as String?).toBoolean()) { + substitute(module("com.bitwarden:sdk-android")) + .using(module("com.bitwarden:sdk-android:LOCAL")) + } + } +} + dependencies { fun standardImplementation(dependencyNotation: Any) { add("standardImplementation", dependencyNotation) @@ -312,4 +333,4 @@ tasks { getByName("sonar") { dependsOn("check") } -} +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 60807ef45..c659d0bf7 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -33,6 +33,9 @@ dependencyResolutionManagement { password = userProperties["gitHubToken"] as String? ?: System.getenv("GITHUB_TOKEN") } } + if ((userProperties["localSdk"] as String?).toBoolean()) { + mavenLocal() + } } }