Reputation: 730
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.
Upvotes: 4
Views: 7296
Reputation: 5622
If you'd like the version to be the currently checked-out reference abbreviation (branch name or tag name) , then this is all it takes:
version 'git rev-parse --abbrev-ref HEAD'.execute().getText().trim()
However, this will set version as "HEAD" if head is not a branch or a tag. If you'd like it that the version will be based on the short hash under these circumstances, then you can do the following:
version 'git rev-parse --abbrev-ref HEAD'.execute().getText().trim()
if (version.equals('HEAD')) {
version 'git rev-parse --short HEAD'.execute().getText().trim()
}
Upvotes: 1
Reputation: 730
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.
Upvotes: 13