gradle-android-git-version
gradle-android-git-version copied to clipboard
Different format per buildType?
Is it possible to use different version formats for release and debug? For example, for debug builds I'd like to include the commit hash, but omit it for release.
I was able to work around this by stripping parts of the string in when handling the release variant, but maybe there's a simpler way to do it with the plugin:
androidGitVersion {
codeFormat 'MMNNBBB'
commitHashLength = 4
format '%tag%%.count%%-commit%'
untrackedIsDirty = false
}
android.applicationVariants.all { variant ->
if (variant.buildType.name == "release") {
variant.outputs.each { output ->
output.versionCodeOverride = androidGitVersion.code()
output.versionNameOverride = stripVersionNameForRelease(androidGitVersion.name())
}
}
}
static def stripVersionNameForRelease(String versionName) {
return versionName.substring(0, versionName.indexOf("-"))
}
What you're doing is the only way right now. But having totally separate formats for "release" branches is a great idea. Instead of hideBranches
, we could have releaseBranches
and releaseFormat
.
@ghost https://github.com/ReactiveCircus/app-versioning#custom-rules Here's an alternate approach to the same problem from another project -- allow overriding the plugin's config per build variant.