Git-based build.gradle

I am a Minecraft modem and I use the ForgeGradle plugin to create mods.

I'm currently trying to set up a version control scheme based on my modifications and git hashes. On an arch linux PKGBUILD system, I would use:

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

which will end up being something like strings r392.2cc2ebc

I am trying to do 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 ?in every part of the version. Gradle 2.0 suggestions?

Further research due to comment by Peter Niederwieser forces me to run an assembly with an information flag, and it seems that new lines are stuck in 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.
+4
2

, , , :

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

, bash .

+8

, ( ), , :

version 'git rev-parse --abbrev-ref HEAD'.execute().getText().trim()

"", . , , :

version 'git rev-parse --abbrev-ref HEAD'.execute().getText().trim()
if (version.equals('HEAD')) {
    version 'git rev-parse --short HEAD'.execute().getText().trim()
}
+1

All Articles