I have a pom.xml file like:
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.plugins</groupId>
<artifactId>testplugin</artifactId>
<packaging>grails-plugin</packaging>
<version>1.0</version>
<name>testplugin</name>
<description>testplugin</description>
<dependencies>
<dependency>
<groupId>org.grails</groupId>
<artifactId>grails-plugin-async</artifactId>
<version>${grails.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>grails</id>
<name>grails</name>
<url>http://repo.grails.org/grails/core</url>
</repository>
</repositories>
</project>
I need to add some more nodes in the above xml file using groovy xml slurper. For example: wants to add the below configuration inside the existing xml file.
<pluginRepositories>
<pluginRepository>
<id>synergian-repo</id>
<url>https://raw.github.com/synergian/wagon-git/releases</url>
</pluginRepository>
</pluginRepositories>
Similarly, I want to add new dependency element inside dependencies element:
<dependency>
<groupId>org.grails.plugins</groupId>
<artifactId>tomcat</artifactId>
<version>7.0.42</version>
<type>zip</type>
<scope>provided</scope>
</dependency>
How can I achieve this? I looked at some examples & written code like:
new File("pom.xml").withWriter('UTF-8') { w ->
def xml = new MarkupBuilder(w)
xml.pluginRepositories {
pluginRepository {
id "synergian-repo"
url "https://raw.github.com/synergian/wagon-git/releases"
}
}
}
But the above code replaces the whole file with only new text.