buildscript { repositories { mavenCentral() } dependencies { classpath group: "org.ajoberstar", name: "gradle-git", version: "1.3.0" } } import org.ajoberstar.grgit.Grgit task(writeVersion) { doLast { def grgit = Grgit.open(dir: project.rootDir) def version = grgit.resolve.toCommit("HEAD").id def niceVersion = grgit.describe() grgit.close() new File("src/generated/resources").mkdirs() project.file("src/generated/resources/version.yaml").withWriter { out -> out.println "id: ${version}" out.println "nice: ${niceVersion}" } } } sourceSets { main { resources { srcDirs += "src/generated/resources" } } } processResources { dependsOn(writeVersion) }