54

How do you run maven with the versions plugin to update the version inside several pom.xml files and not get the annoying pom.xml.versionsBackup files? (I have my poms in version control, so I don't need a backup).

I run this command to update the version:

mvn versions:set -DnewVersion=3.8.0-SNAPSHOT

Jaap
  • 641
  • 12
  • 19
Jess
  • 23,901
  • 21
  • 124
  • 145

3 Answers3

109

To prevent creating backup files, use generateBackupPoms instead:

mvn versions:set -DgenerateBackupPoms=false -DnewVersion=3.9.0-SNAPSHOT

I also saw that you can set up generateBackupPoms in the plugin section of a pom.xml if you want to do it that way.

Note if you are using eclipse, you can run the command using a run configuration like this:

enter image description here

See also: http://www.mojohaus.org/versions-maven-plugin/set-mojo.html

Peter Wippermann
  • 4,125
  • 5
  • 35
  • 48
Jess
  • 23,901
  • 21
  • 124
  • 145
  • 9
    That helped, but a tip: with `-DnewVersion=${string_prompt}` eclipse presents a dialog for you to enter the version number, so you don't need to update your run configuration all the time (I also put the -D parameters to the Parameters further down, without the `-D` there). I think its much more convenient. – kratenko Nov 27 '15 at 14:39
  • 1
    Awesome @kratenko. I like it! – Jess Nov 30 '15 at 13:48
  • only problem: if you hit cancel that prompt (escape), it still runs and does useless bogus. Would like to have a way to catch that cancel, but failed to find one. If anyone knows, please respond here. – kratenko Jan 05 '16 at 14:50
  • Awesome, would be nice to know if we can do this in Intellij too. I'll start searching. – Obaid Feb 23 '16 at 09:04
  • Its not working on my jenkins machine. I am using -DgenerateBackupPoms=false but still backup poms are created. This is my command -> ```mvn build-helper:parse-version versions:set \ -DnewVersion=\\\${parsedVersion.majorVersion}.\\\${parsedVersion.minorVersion}.\\\${parsedVersion.nextIncrementalVersion}-SNAPSHOT -DprocessAllModules -DgenerateBackupPoms=false``` – lostintranslation Sep 18 '18 at 05:40
  • 1
    In Eclipse, the `newVersion=${string_prompt}` will only work if you add in the **Parameter** section below, but it works. – cbaldan Mar 20 '19 at 18:34
35

After mvn versions:set, run the command mvn versions:commit.

All of the pom backups will be deleted.

Jess
  • 23,901
  • 21
  • 124
  • 145
eXistPierre
  • 991
  • 9
  • 17
8

mvn versions:set -DgenerateBackupPoms=false deletes the backups and will also ask the new version to be set instead of passing the version in the command.

Jess
  • 23,901
  • 21
  • 124
  • 145