From 69494180c7617f1b8a5053d97cfd6ab45b370069 Mon Sep 17 00:00:00 2001 From: Devin Morgan Date: Thu, 28 Sep 2023 15:05:46 -0400 Subject: [PATCH] Have ext.PUBLISH_VERSION be source of truth (#118) It turns out we can use variables in groovy to declare the release version of our package in one variable (the variable that our sonatype repository happens to look for the release version) and then reference that variable in another place location (in our case we want to reference it so we can expose it on the `BuildConfig` to reference it in logs at runtime) NOTE: * I moved the ext block to the top of the build.gradle file so that the PUBLISH_VERSION variable would exist by the time the android block executes * To reduce coupling on `BuildConfig`, I opted to continue the pattern of exposing the PUBLISH_VERSION via the `EnvConfig` object. We can change this later if not a good idea --- forage-android/build.gradle | 42 ++++++++++--------- .../forage/android/core/EnvConfig.kt | 10 ++--- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/forage-android/build.gradle b/forage-android/build.gradle index 5c6a42be..e51db653 100644 --- a/forage-android/build.gradle +++ b/forage-android/build.gradle @@ -5,6 +5,26 @@ plugins { id("org.jetbrains.kotlinx.kover") version "0.6.1" } +ext { + PUBLISH_GROUP_ID = 'com.joinforage' + PUBLISH_VERSION = '3.3.0' + PUBLISH_ARTIFACT_ID = 'forage-android' + PUBLISH_DESCRIPTION = 'Forage Android SDK' + PUBLISH_URL = 'https://github.com/teamforage/forage-android-sdk' + PUBLISH_LICENSE_NAME = 'MIT License' + PUBLISH_LICENSE_URL = + 'https://github.com/teamforage/forage-android-sdk/blob/main/LICENSE' + PUBLISH_DEVELOPER_ID = 'owenkim' + PUBLISH_DEVELOPER_NAME = 'Owen Kim' + PUBLISH_DEVELOPER_EMAIL = 'owenkim@forage.com' + PUBLISH_SCM_CONNECTION = + 'scm:git:github.com:teamforage/forage-android-sdk.git' + PUBLISH_SCM_DEVELOPER_CONNECTION = + 'scm:git:ssh://github.com:teamforage/forage-android-sdk.git' + PUBLISH_SCM_URL = + 'https://github.com/teamforage/forage-android-sdk/tree/main' +} + android { namespace 'com.joinforage.forage.android' compileSdk 33 @@ -15,6 +35,8 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" + + buildConfigField 'String', 'PUBLISH_VERSION', "\"${PUBLISH_VERSION}\"" } buildTypes { @@ -81,24 +103,6 @@ dependencies { androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' } -ext { - PUBLISH_GROUP_ID = 'com.joinforage' - PUBLISH_VERSION = '3.2.0' - PUBLISH_ARTIFACT_ID = 'forage-android' - PUBLISH_DESCRIPTION = 'Forage Android SDK' - PUBLISH_URL = 'https://github.com/teamforage/forage-android-sdk' - PUBLISH_LICENSE_NAME = 'MIT License' - PUBLISH_LICENSE_URL = - 'https://github.com/teamforage/forage-android-sdk/blob/main/LICENSE' - PUBLISH_DEVELOPER_ID = 'owenkim' - PUBLISH_DEVELOPER_NAME = 'Owen Kim' - PUBLISH_DEVELOPER_EMAIL = 'owenkim@forage.com' - PUBLISH_SCM_CONNECTION = - 'scm:git:github.com:teamforage/forage-android-sdk.git' - PUBLISH_SCM_DEVELOPER_CONNECTION = - 'scm:git:ssh://github.com:teamforage/forage-android-sdk.git' - PUBLISH_SCM_URL = - 'https://github.com/teamforage/forage-android-sdk/tree/main' -} + apply from: "${rootProject.projectDir}/scripts/publish-module.gradle" diff --git a/forage-android/src/main/java/com/joinforage/forage/android/core/EnvConfig.kt b/forage-android/src/main/java/com/joinforage/forage/android/core/EnvConfig.kt index 5082237d..768d6f16 100644 --- a/forage-android/src/main/java/com/joinforage/forage/android/core/EnvConfig.kt +++ b/forage-android/src/main/java/com/joinforage/forage/android/core/EnvConfig.kt @@ -1,5 +1,6 @@ package com.joinforage.forage.android.core +import com.joinforage.forage.android.BuildConfig import com.joinforage.forage.android.ui.ForageConfig internal enum class EnvOption(val value: String) { @@ -20,11 +21,10 @@ internal sealed class EnvConfig( val ldMobileKey: String, val ddClientToken: String ) { - // This is how we currently offer access to the the release - // version to code at runtime. It is essential that this - // value stay in sync with forage-android/build.gradle's - // PUBLISH_VERSION value. - val PUBLISH_VERSION: String = "3.2.0" + // For the time being, I figure we can consume BuildConfig in exactly + // one spot (here) to reduce the pieces of source code have to couple + // to BuildConfig. + val PUBLISH_VERSION: String = BuildConfig.PUBLISH_VERSION object Dev : EnvConfig( FLAVOR = EnvOption.DEV,