Created
October 19, 2015 11:16
-
-
Save bugs84/bb0080da0cc35c776031 to your computer and use it in GitHub Desktop.
Gradle - Get Hg Mercurial revision
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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