6

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?

baratali
  • 443
  • 7
  • 16
  • Why do you need the version in build.gradle directly? – Vampire Feb 14 '17 at 13:26
  • @Vampire, I don't want one more file in my project. I would like to keep all gradle stuff in one place. – baratali Feb 14 '17 at 13:33
  • @Barataliba `gradle.properties` is a standard gradle mechanism how to add project properties. You should reconsider having one extra file in your project. – MartinTeeVarga Feb 14 '17 at 21:41
  • @sm4, I already have two gradle files: "build.gradle" and "settings.gradle". I don't want to create a third one if there is a way to keep version in "build.gradle" file. – baratali Feb 16 '17 at 13:52

1 Answers1

13

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\'')
}
Vampire
  • 35,631
  • 4
  • 76
  • 102
  • What if the same version is present elsewhere in build.gradle. Say a depdendency with the same version? – user672009 Jan 22 '19 at 20:29
  • Not a problem, after all, the replacing expects that the version is stored in a properties file. It replaces the value of the property called version (plus additional ones you configured). That's also why you need to do the additional replacing to add the quotes. – Vampire Jan 22 '19 at 22:58