Skip to content

Commit

Permalink
Have ext.PUBLISH_VERSION be source of truth (#118)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
devinmorgan authored Sep 28, 2023
1 parent 7b193b5 commit 6949418
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
42 changes: 23 additions & 19 deletions forage-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]'
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
Expand All @@ -15,6 +35,8 @@ android {

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"

buildConfigField 'String', 'PUBLISH_VERSION', "\"${PUBLISH_VERSION}\""
}

buildTypes {
Expand Down Expand Up @@ -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 = '[email protected]'
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"
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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,
Expand Down

0 comments on commit 6949418

Please sign in to comment.