I need to extract the Maven GAV (groupId, artifactId, version) from a large number of pom.xml
files. Not all of the POMs have a parent POM declaration, so the inheritance between parent GAV and project GAV needs to be taken into account.
I'd only like to use tools that can be easily scripted in a linux shell, e.g. bash.
The best solution I could find is using an XSL transformation. Create a file
extract-gav.xsl
with the following content:This transformation can then be invoked in a shell (assuming that you have the libxslt installed) with th command
xsltproc extract-gav.xsl pom.xml
This produces the output in the following format:
If you need a different format, the XSL transformation should be easy enough to adapt so that it suits your needs. E.g. the following transformation writes the GAV as tab-separated plain text:
I use a groovy script called pom that I placed on PATH. It looks like this:
Now you can extract values like this: