0

我有一个 maven 项目,其中许多子 pom 的依赖项版本都列在<dependencyManagement>父 pom 的标签下。这个 pom 树可以有任何深度。

我的问题是,当给出 pom.xml 时,如何使用 java 解决其依赖项的确切(继承)版本?

所需的输出是我们mvn dependency:resolve -DincludeTransitive=false在 pom.xml 文件上运行时给出的

例如,假设父 pom 在其中定义了以下依赖项<dependencyManagement>

<dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>group-a</groupId>
        <artifactId>artifact-a</artifactId>
        <version>1.0</version>
      </dependency>
      <dependency>
        <groupId>group-a</groupId>
        <artifactId>artifact-b</artifactId>
        <version>1.0</version>
        <type>bar</type>
        <scope>runtime</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

并且子 pom.xml 具有以下依赖项

<dependencies>
    <dependency>
      <groupId>group-a</groupId>
      <artifactId>artifact-a</artifactId>
    </dependency>
    <dependency>
      <groupId>group-a</groupId>
      <artifactId>artifact-b</artifactId>
    </dependency>
  </dependencies>

如何以编程方式使用 Java检索group-a:artifact-agroup-b:artifact-b的版本?

谢谢。

4

1 回答 1

1

尝试运行

mvn dependency:tree -Doutput=/path/to/file

或者

mvn dependency:tree -DoutputFile=/path/to/file

来自 maven 文档:http ://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html

于 2014-02-10T20:42:40.000 回答