Reputation: 817
Given that I have Dependency groupId and artifactId, how do I extract the version for this dependency from the pom.xml file?
Example: I want to be able to extract the dependency version below if I query using the artifactId and groupId.
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
</dependency>
I want to assign the version to a global environment variable i.e. DEP_VERSION=1.6
Upvotes: 3
Views: 1766
Reputation: 26858
You can use the Maven Dependency Plugin:
mvn dependency:tree -Dincludes=com.google.guava:guava
It will output something like:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MyProject 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ project-server ---
[INFO] com.company.project:project-server:jar:0.0.1-SNAPSHOT
[INFO] \- com.google.guava:guava:jar:19.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.016 s
[INFO] Finished at: 2016-04-06T16:58:55+02:00
[INFO] Final Memory: 21M/437M
[INFO] ------------------------------------------------------------------------
Upvotes: 0
Reputation: 3471
It is an xml. Trivially you could make a parsing of the file.
Upvotes: 0