rzvvfg
Last Updated: February 25, 2016
·
3.731K
· lorin

Accessing git branch name in gradle

Here's an example build.gradle snippet that uses gradle-git to retrive the branch name, which is used to set the version.

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'org.ajoberstar:gradle-git:1.1.0'
  }
}

apply plugin: 'java'
import org.ajoberstar.grgit.*
ext.repo = Grgit.open(project.file('.'))

version = "1.1-${ext.repo.branch.current.name}"