2

I saw that a lot of people is using git tag to read the version during build and then assemble however i would like to do the opposite.

I already have my version name and code dynamically created in my build.gradle and i want to tag the current git commit every time i do an assemble (which changes the version name) with the version name PLUS the current variant name (so i need it to be variant independent). What i am not able to do is read the current version name from the variant i am building, so, something like:

task gitTag(type: Exec) {
    exec {
        currentVersionName = android.variant.name
        commandLine 'git tag -a ' + currentVersionName
    }
}

tasks.whenTaskAdded { task ->
    if (task.name == 'assemble') {
        task.dependsOn = gitTag
    }
}

On top of this, since it appears no one is doing this, is this a bad approach?

FrankMonza
  • 2,024
  • 16
  • 26
  • I don't quite understand the question. Do you need latest tag to know (programatically) the latest version? If yes, you can use modified `GIT-VERSION-GEN` approach with `git describe --match "v[0-9]*" --abbrev=0 HEAD` (assumung that you use `vX.Y.Z` tags to name released versions). – Jakub Narębski Feb 20 '15 at 17:56
  • 1
    No, i need to execute "git tag" every time i run "assembleRelease" or "assembleBeta" with the correct tag name after variant evaluation – FrankMonza Feb 21 '15 at 20:10

0 Answers0