Skip to content

Instantly share code, notes, and snippets.

View michaelbel's full-sized avatar
🏠
Working from home

Michael Bely michaelbel

🏠
Working from home
View GitHub Profile
@michaelbel
michaelbel / commits_count.gradle
Last active January 29, 2023 03:01
Git commits count as version code (Groovy & Kotlin implementation)
static def gitVersion() {
def result = "git rev-list HEAD --count".execute().text.trim() // unix
if (result.empty) result = "PowerShell -Command git rev-list HEAD --count".execute().text.trim() // windows
if (result.empty) throw new RuntimeException("Could not generate versioncode on this platform? Cmd output: ${result.text}")
return result.toInteger()
}
android {
defaultConfig {
versionCode gitVersion()