Skip to content

Commit

Permalink
[GRADLE] Add function to auto increment minor version name
Browse files Browse the repository at this point in the history
  • Loading branch information
peterkrauz committed Nov 24, 2020
1 parent 1343a05 commit e4bc21a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# Grimoire :crystal_ball: :open_book:
## What is this
> ## What is this
Grimoire (pronounced **gruhm · waar**) is a hobby app that employs several Android modern technologies and best practices. <br>
It is currently a work in progress being slowly refined weekend by weekend, for usage on my not-so-regular tabletop RPG gaming sessions.


> ## Characteristics
Besides having been built 100% with Kotlin, it has a [single-activity](app/src/main/java/com/peterkrauz/grimoire/MainActivity.kt) and performs navigation
with Jetpack's Navigation Component. Fragments and [ViewModel](https://developer.android.com/topic/libraries/architecture/viewmodel)s interact with one another
through the usage of [LiveData](https://developer.android.com/topic/libraries/architecture/livedata)s, employing a unidirectional data flow on our presentation layer.


> ## Architecture
In search of achieving a [Clean Architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html), the common monolithic Android structure
was dismembered into multiple modules.


> ## Technologies
* [Room](https://developer.android.com/topic/libraries/architecture/room)
* [Hilt](https://developer.android.com/training/dependency-injection/hilt-android)
Expand Down
9 changes: 8 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ android {
minSdkVersion AndroidConfig.minSdkVersion
targetSdkVersion AndroidConfig.targetSdkVersion
versionCode AndroidConfig.versionCode
versionName AndroidConfig.versionName
versionName "${AndroidConfig.majorVersion}.${AndroidConfig.mediumVersion}.${generateVersionCode()}"
testInstrumentationRunner AndroidConfig.testInstrumentationRunner
ext.betaDistributionGroupAliases = firebaseBetaGroups

Expand Down Expand Up @@ -98,4 +98,11 @@ dependencies {
implementation project(ModulePaths.tags)
implementation project(ModulePaths.notes)
implementation project(ModulePaths.characters)
}

static def generateVersionCode() {
def result = "git rev-list HEAD --count".execute().text.trim()
if(result.empty) result = "PowerShell -Command git rev-list HEAD --count".execute().text.trim()
if(result.empty) throw new RuntimeException("Could not generate versioncode on this platform: cmd output: ${result.text}")
return result.toInteger()
}
4 changes: 3 additions & 1 deletion buildSrc/src/main/java/AndroidConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ object AndroidConfig {
const val minSdkVersion = 21
const val targetSdkVersion = 30
const val versionCode = 1
const val versionName = "0.0.3"
const val versionName = "0.0.4"
const val majorVersion = 0
const val mediumVersion = 0
const val testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
const val consumerProguardFile = "consumer-rules.pro"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fun AppCompatActivity.snackBar(
Snackbar.make(
hostView,
message,
Snackbar.LENGTH_LONG
Snackbar.LENGTH_SHORT
).apply {
view.setBackgroundResource(type.backgroundRes)
}.show()
Expand Down
10 changes: 9 additions & 1 deletion module-config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {
minSdkVersion AndroidConfig.minSdkVersion
targetSdkVersion AndroidConfig.targetSdkVersion
versionCode AndroidConfig.versionCode
versionName AndroidConfig.versionName
versionName "${AndroidConfig.majorVersion}.${AndroidConfig.mediumVersion}.${generateVersionCode()}"

testInstrumentationRunner AndroidConfig.testInstrumentationRunner
consumerProguardFiles AndroidConfig.consumerProguardFile
Expand All @@ -29,3 +29,11 @@ android {
jvmTarget = AndroidConfig.jvmTarget
}
}


static def generateVersionCode() {
def result = "git rev-list HEAD --count".execute().text.trim()
if(result.empty) result = "PowerShell -Command git rev-list HEAD --count".execute().text.trim()
if(result.empty) throw new RuntimeException("Could not generate versioncode on this platform: cmd output: ${result.text}")
return result.toInteger()
}

0 comments on commit e4bc21a

Please sign in to comment.