Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

build.gradle versioning based on git

Tags:

git

gradle

groovy

I'm a minecraft modder, and I use the ForgeGradle plugin to build my mods.

I'm currently attempting to setup a versioning scheme based on my git revisions and hash. Under arch linux's PKGBUILD system I would use:

pkgver() {
  cd $_pkgbase
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

which would end up with something along the lines of r392.2cc2ebc

I'm attempting with the following:

ext.revision = 'git rev-list --count HEAD'.execute()
ext.hash     = 'git rev-parse --short HEAD'.execute()
version      = "r${revision.text}.${hash.text}"

which gets me almost what I need, r70?.11ae542?; not sure how to get rid of the ? in each portion of the version. Gradle 2.0, suggestions?

Further investigation due to Peter Niederwieser's comment lead me to run build with the info flag, and it does seem newlines are getting stuck into the file name:

Executing task ':reobf' (up-to-date check took 0.004 secs) due to:
  Output file build/libs/CreepyPastaCraft-1.7.x-r70
.11ae542
-universal.jar has changed.
like image 754
hanetzer Avatar asked Dec 09 '22 07:12

hanetzer


1 Answers

Well, as Peter has declined to turn his comment into an answer, I shall answer my own question for the benefit of others looking to do the same:

ext.revision = 'git rev-list --count HEAD'.execute().text.trim()
ext.hash = 'git rev-parse --short HEAD'.execute().text.trim()
version = "r${revision}.${hash}"

This yeilds the same result as the bash expression in my question.

like image 120
hanetzer Avatar answered Dec 10 '22 20:12

hanetzer