简体   繁体   English

从POM中提取Maven依赖版本

[英]Extract Maven Dependency Version from POM

Given that I have Dependency groupId and artifactId, how do I extract the version for this dependency from the pom.xml file? 鉴于我具有Dependency groupId和artifactId,我如何从pom.xml文件中提取此依赖项的版本?

Example: I want to be able to extract the dependency version below if I query using the artifactId and groupId. 示例:如果我使用artifactId和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 ie DEP_VERSION=1.6 我想将版本分配给全局环境变量,即DEP_VERSION = 1.6

It is an xml. 这是一个xml。 Trivially you could make a parsing of the file. 您可以轻松地对该文件进行解析。

You can use the Maven Dependency Plugin : 您可以使用Maven依赖插件

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] ------------------------------------------------------------------------

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM