0

I want to increment SNAPSHOT version in pom.xml file without using maven release plugin. Current version is,

0.0.1-SNAPSHOT

expected version is,

0.1.1-Snapshot

How can I do this by accessing pom.xml file? I am working on jenkins maven project. can I use sed command for this?

Janith
  • 217
  • 1
  • 6
  • 15
  • 2
    You could use the [versions-maven-plugin](https://www.mojohaus.org/versions-maven-plugin/set-mojo.html) in combination with [build-helper-maven-plugin](https://www.mojohaus.org/build-helper-maven-plugin/parse-version-mojo.html)... – khmarbaise Oct 31 '18 at 07:09
  • yes, but the requirement is to get the version by shell commands. I used `grep`, `head` and `sed` commands to change the version. – Janith Oct 31 '18 at 08:02
  • It does not really make sense to use the shell cause you are working with an XML structure so do not try to make it work with shel (grep etc.)...it will fail sometimes... See https://stackoverflow.com/a/53099850/296328 – khmarbaise Nov 01 '18 at 12:59

2 Answers2

0

I used this command to change the pom version and it is working

grep -ri "<version>" pom.xml |head -n 1 | sed -i 's/>0.0.1-SNAPSHOT</>0.1.1- 
SNAPSHOT</g' pom.xml
Janith
  • 217
  • 1
  • 6
  • 15
0

I guess you could give xmlstarlet a try:

$ xmlstarlet ed -N mvn=http://maven.apache.org/POM/4.0.0 -u /mvn:project/mvn:version -v 0.1.1-Snapshot pom.xml

XMLStarlet is obviously XML-aware and as such it will be smarter if you move stuff around and will only update what you tell it to, since it uses XPath. For instance, having other <version> tags in dependencies and parent will be handled correctly as well.

Please be aware that "snapshot" should be in caps.

Link to its documentation: http://xmlstar.sourceforge.net/docs.php

Daniel
  • 4,033
  • 4
  • 24
  • 33