Gradle release plugin which stores version in build.gradle

baratali picture baratali · Feb 14, 2017 · Viewed 7k times · Source

I'm converting my application from maven to gradle, and I'm looking for maven-release-plugin alternative for gradle.

All I need from the plugin is:

  • remove '-SNAPSHOT' suffix from the version and commit to git repo
  • create new git tag on this commit
  • bump version in build.gradle (like pom.xml), and add '-SNASPHOT' suffix

I guess, the most popular one is Gradle Release Plugin (https://github.com/researchgate/gradle-release). It works just fine, however, it stores the version in a separate file "gradle.properties". I need to store this version in "build.gradle" file (like a version in pom.xml).

I also tested following plugins, but they don't store version in build.gradle too:

Are there any Gradle plugins which can work with version in "build.gradle" file?

Answer

Vampire picture Vampire · Feb 14, 2017

You could e. g. make

plugins {
    id 'net.researchgate.release' version '2.4.0'
}

version = '1.2.3'

release {
    versionPropertyFile = 'build.gradle'
}

updateVersion.doLast {
    def buildGradle = file('build.gradle')
    buildGradle.text = buildGradle.text.replaceFirst(~/version = (\d++\.\d++\.\d++)/, 'version = \'$1\'')
}