1

i have a pom.xml contain a line

<version>x.y.z-tag</version>

where tag could be: snapshot, alpha, beta or release.

and x.y.z is a number version like: 1.0.0 or 1.2.1 ....

i want to make a change to that line by a given parameter. for instance:

existing version: <version>1.0.0-snapshot</version>

given parameter: 1.0.1-alpha

output: <version>1.0.1-alpha</version>

./script.sh newVersion pom.xml

PS: pom.xml contain lot of lines start with <version> ... so my changes should be applied to <version> with a pattern : x.y.z-tag

1
#!/bin/sh            
tag=$(grep '<version>' $2 | sed 's/<version>[^-]*-\(.*\)<\/version>/\1/')
sed -i "s/<version>.*<\/version>/<version>$1-${tag}<\/version>/" $2

save this as script.sh, make it executable (chmod +x script.sh) and run it with:

./script.sh <new_version> pom.xml
  • thank you for your quick answer, i want to verify before if the <version>...</version> match to the pattern *-snapshot or *-release... and replace it by the given version. your solution it change every <version>... in pom.xml. – Gimbo Nov 2 '15 at 12:18
  • I edited the answer. – blissini Nov 2 '15 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.