Previously I used below command to take the version in pom.xml and increment it from one. Before increment snapshot version is, 0.0.1
#!/bin/bas
Use an XML-aware tool. For example, in xsh you can write
open pom.xml ;
register-namespace m http://maven.apache.org/POM/4.0.0 ;
for //m:version
set . xsh:subst(., '(?<=\.)([0-9]+)$', '$1+1', 'e') ;
save :b ;
Which changes "0.0.1" to "0.0.2".
To also increment the version if -SNAPSHOT
is present, the regular expression becomes a bit more complex:
xsh:subst(., '(?<=\.)([0-9]+)(?=$|-SNAPSHOT$)', '$1+1', 'e') ;
^ ^ ^ ^ ^
| | | | |
| | Followed by | Evaluate replacement
Preceded | end of string | as code
by a dot At least or -SNAPSHOT plus |
one digit end of string Add one
to the 1st
capture group