I have a file pom.xml, which needs to have the version with a SNAPSHOT appended to it. At times, the SNAPSHOT is missing, which results in the build failing. I'm trying to replace it with SNAPSHOT if it doesn't exist.
Actual:
<artifactId>package1</artifactId>
<version>1.0.0</version>
Desired:
<artifactId>package1</artifactId>
<version>1.0.0-SNAPSHOT</version>
Since the artifactId is not going to be the same across all the projects, I tried to search for a pattern that starts from </artifactId> to </version> and replace it with the SNAPSHOT text added to it. This has resulted in replacing the text till the last version available in pom.xml.
I've tried the following:
cat pom.xml | sed ':a;N;$!ba;1,/<\/artifactId>/s/<\/artifactId><version>[0-9]*.[0-9]*.[0-9]*<\/version>/<\/artifactId><version>1.0.0-SNAPSHOT<\/version>/g'
(Not working at all as it's unable to find the end of line).
cat common-pom.xml | sed ':a;N;$!ba;0,/<\/artifactId>/s/<\/artifactId>.*<\/version>/<\/artifactId><version>0.0.0-SNAPSHOT<\/version>/g'
(Is able to do the changes, but it's replacing all the text till the last version available in pom.xml).
How do I stop the replacement to the first occurrence in a multi line replacement?