gradle-android-git-version icon indicating copy to clipboard operation
gradle-android-git-version copied to clipboard

Different format per buildType?

Open fejd opened this issue 4 years ago • 2 comments

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("-"))
}

fejd avatar Oct 15 '20 14:10 fejd

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.

gladed avatar Oct 15 '20 16:10 gladed

@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.

ivanbartsov avatar Jan 18 '21 07:01 ivanbartsov