Skip to content

Instantly share code, notes, and snippets.

@bugs84
Created October 19, 2015 11:16
Show Gist options
  • Save bugs84/bb0080da0cc35c776031 to your computer and use it in GitHub Desktop.
Save bugs84/bb0080da0cc35c776031 to your computer and use it in GitHub Desktop.
Gradle - Get Hg Mercurial revision
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.aragost.javahg:javahg:0.4'
}
}
task revision << {
println "Build revision: $scmRevision"
}
import com.aragost.javahg.Changeset
import com.aragost.javahg.Repository
import com.aragost.javahg.commands.ParentsCommand
String getHgRevision() {
def repo = Repository.open(projectDir)
def parentsCommand = new ParentsCommand(repo)
List<Changeset> changesets = parentsCommand.execute()
if (changesets == null || changesets.size() != 1) {
def message = "Exactly one was parent expected. " + changesets
throw new Exception(message)
}
return changesets[0].node
}
ext {
scmRevision = getHgRevision()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment