Decision:
POM_VERSION=$( \ xmlstarlet sel \ -N x='http://maven.apache.org/POM/4.0.0' \ -t \ -v '//x:project/x:version/text()' \ pom.xml \ )
Explanation:
You can do this in one layer using the XPath tool from the command line, for example, mentioned in the section How to execute XPath single-line shells from the shell? ". I chose XMLStarlet , but they all have similar syntax.
When analyzing POM, you should consider namespaces. The docs here helped me figure this out.
To get the text for an element in XPath, you use the text () function, as described in XPath: select the text node .
My POM looks like this:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.foo.bar</groupId> <artifactId>foobar</artifactId> <version>1.0.6-SNAPSHOT</version> <packaging>jar</packaging>
The disadvantage here is that if the namespace changes, you need to change the command.
John Michelau Mar 01 '17 at 20:57 2017-03-01 20:57
source share