鉴于我有Dependency groupId和artifactId,如何从pom.xml文件中提取此依赖项的版本?
示例:如果我使用artifactId和groupId进行查询,我希望能够提取下面的依赖项版本。
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
</dependency>
我想将版本分配给全局环境变量,即DEP_VERSION = 1.6
答案 0 :(得分:0)
它是一个xml。 平凡的,你可以解析文件。
答案 1 :(得分:0)
您可以使用Maven Dependency Plugin:
mvn dependency:tree -Dincludes=com.google.guava:guava
它将输出如下内容:
[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] ------------------------------------------------------------------------