0

I want to update the version of my Maven project to the release version corresponding to the current snapshot version. E.g. 1.2-SNAPSHOT should become 1.2. In other words, I just want to remove the -SNAPSHOT suffix from the version. I want to do this in a non-interactive way, so that my CI tool can perform this action.

I know this can be done with either the maven-release-plugin or the maven-versions-plugin and probably other plugins as well. I have a preference for the maven-versions-plugin because it handles aggregator projects nicely.

Both plugins prompt for the new version, but allow you to provide the version on the command line. How to I provide the new version relative to the current snapshot version? As said, I just want to remove the -SNAPSHOT part.

So to be clear:

  • I only want to update the version of the project, not all the other stuff that the release plugin offers.
  • I don't want to specify the version number, but just update the version to "whatever there's before -SNAPSHOT".
Rinke
  • 6,095
  • 4
  • 38
  • 55

3 Answers3

0

The maven-release-plugin does exactly what you ask for - and can be run in non-interactive mode to perform the following steps:

Build the project

Tag the code

Push the changes to your SCM

amend the version to a release one

build again

push the versioned jar/war/ear/zip to the repository of your choice

tag and push

set the version number to the next snapshot version

etc.

All done automatically.

TrueDub
  • 5,000
  • 1
  • 27
  • 33
  • Yes, but I want to update the version to "whatever there's before `-SNAPSHOT`", and not specify the version specifically on the command line. – Rinke Jul 06 '16 at 13:31
  • Yes there is, check the answer [here](http://stackoverflow.com/q/23501119/5606016), all automated in a profile – A_Di-Matteo Jul 06 '16 at 13:33
  • That's exactly what the non-interactive mode does - if your version is 1.2.3-SNAPSHOT, it will create a release of 1.2.3 and your next version will be 1.2.4-SNAPSHOT – TrueDub Jul 06 '16 at 14:54
0

With your CI tool, you should be able to edit the tag in the POM Directly.

This is a snippet from a small project of mine.

<modelVersion>4.0.0</modelVersion>
<groupId>com.organization</groupId>
<artifactId>pdf_tiff_conversion</artifactId>
<version>1.0-SNAPSHOT</version> // Edit this tag
<packaging>jar</packaging>
Scrambo
  • 579
  • 5
  • 17
0

Use versions-maven-plugin:

mvn org.codehaus.mojo:versions-maven-plugin:2.1:set -DnewVersion=1.2 -DgenerateBackupPoms=false

This unfortunatelly forces you to provide the version number (1.2), it won't strip the -SNAPSHOT, but it is a much simpler solution then the release plugin.

Krzysztof Krasoń
  • 26,515
  • 16
  • 89
  • 115
  • This is indeed the solution closest to what I want that I found so far. My question is about how to say "update to whatever there's before `-SNAPSHOT`. I was hoping there's some clever way to do this. – Rinke Jul 06 '16 at 13:30
  • I think http://stackoverflow.com/questions/3545292/how-to-get-maven-project-version-to-the-bash-command-line might help for retrieval of current version, some sed to remove the `-SNAPSHOT` – Krzysztof Krasoń Jul 06 '16 at 13:38
  • @krzyk using the versions plugin you can still drop the snapshot without any interaction, check the answer [here](http://stackoverflow.com/q/23501119/5606016) – A_Di-Matteo Jul 06 '16 at 13:38