0

im looking for a structured method in JAVA to retrieve value from tag in pom.xml then set a new value to this same tag and save it back to the same pom.xml .

for example i like to get the value of : parent.version and change it to 1.3.33 and save it to the same pom.xml

<modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>com.foo</groupId>
    <artifactId>test1</artifactId>
    <version>1.2.1</version>
</parent>

<groupId>com.foo.s.xxx</groupId>
<artifactId>xx-xx</artifactId>
<version>1.1.1</version>
<name>xxx</name>
<packaging>pom</packaging>



<properties>
    <ww.version>1.1.3</ww.version>
</properties>

currently i do it in very naive way :

File pomFile = new File(pomxml);
String content = FileUtils.readFileToString(pomFile);
content = content.replaceAll(oldVersion, newVersion);
user63898
  • 29,839
  • 85
  • 272
  • 514
  • 3
    Are you looking for the versions plugin? `mvn -DnewVersion=[newVersion] versions:set`? https://stackoverflow.com/questions/5726291/updating-version-numbers-of-modules-in-a-multi-module-maven-project – ernest_k Mar 29 '21 at 08:49
  • the version is just example, i need to be able change programmatically any tag value – user63898 Mar 29 '21 at 09:47
  • Then maybe you need to add the `xml` tag, it has very little to do with maven, imo. – ernest_k Mar 29 '21 at 09:50
  • what ? what xml tag in simple words , programmatically edit any tag value and write it back to file – user63898 Mar 29 '21 at 09:53
  • 1
    I suppose I left some ambiguity, sorry. I mean *please tag your SO question with `xml` too*, not add an "xml" tag to your pom.xml file. – ernest_k Mar 29 '21 at 09:55

0 Answers0