How to get SVN revision in Gradle for Android?

I have field (svn revision) in resource. How can I get svn revision in my field using by Gradle, that not to do that by my hands?

  • How to import and run project, in Android Studio 1.1, from Github?
  • Build Unity project with Jenkins failed
  • Create Eclipse Project from Android Git
  • How to revert project back to a previous commit in android studio
  • How to debug android project from git using Jenkins frontend?
  • best way of setting up a phonegap multiplatform project repository
  • How should I structure my project to share classes between an Android client application and a JSP server application?
  • Is there a way to run checkstyle on only files that have changes in VCS?
  • service entry keeps disappearing from manifest
  • Android Studio: Can't start Git
  • StatSVN alternative for Git?
  • Android Emulator Jenkins Plugin not working
  • 2 Solutions collect form web for “How to get SVN revision in Gradle for Android?”

    You could modify the following solution, explained here, which prints out the current SVN revision.

    // File: build.gradle
    task svninfo << {
        new ByteArrayOutputStream().withStream { os ->
            def result = exec {
                executable = 'svn'
                args = ['info']
                standardOutput = os
            def outputAsString = os.toString()
            def matchLastChangedRev = outputAsString =~ /Last Changed Rev: (\d+)/
            println "Latest Changed Revision #: ${matchLastChangedRev[0][1]}"
    // Example output for svn info:
    // Path: .
    // URL:
    // Repository Root:
    // Repository UUID: 9de3ae54-a9c2-4644-a1a1-838cb992bc8e
    // Revision: 33
    // Node Kind: directory
    // Schedule: normal
    // Last Changed Author: mrhaki
    // Last Changed Rev: 33
    // Last Changed Date: 2010-09-03 14:25:41 +0200 (Fri, 03 Sep 2010)

    Try this

    task svnversion {
      description 'Get SVN revision number.'
      new ByteArrayOutputStream().withStream { os ->
        def result = exec {
          executable = 'svnversion'
          standardOutput = os
        ext.revid = os.toString()

    You can test it with

    task printsvn(description: 'Demonstrate calling svnversion task.') << {
      println 'Implementation-Build #' + svnversion.revid

    The results

    $ gradle printsvn
    Implementation-Build #3071


    Total time: 0.776 secs

    Git Baby is a git and github fan, let's start git clone.