如何使用DependencyGraphBuilder以编程方式列出所有传递性依赖项,包括Maven中覆盖的传递性依赖项? [英] How to programmatically list all transitive dependencies, including overridden ones in Maven using DependencyGraphBuilder?

查看:305
本文介绍了如何使用DependencyGraphBuilder以编程方式列出所有传递性依赖项,包括Maven中覆盖的传递性依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与其他问题类似( ),但是我希望能够使用最新的API来做到这一点. maven-dependency-plugin:tree verbose选项已被弃用,在最新的(2.5.1)代码中不执行任何操作,因此没有很好的示例.

This is similar to other questions (like this), but I want to be able to do this with the latest API's. The maven-dependency-plugin:tree verbose option has been deprecated and does nothing in the latest (2.5.1) code, so there is no good example of how to do it.

推荐答案

我相信 jcabi-aether 可以帮助您获取任何Maven工件的所有依赖项的列表,例如:

I believe Aether utility class from jcabi-aether can help you to get a list of all dependencies of any Maven artifact, for example:

File repo = this.session.getLocalRepository().getBasedir();
Collection<Artifact> deps = new Aether(this.getProject(), repo).resolve(
  new DefaultArtifact("junit", "junit-dep", "", "jar", "4.10"),
  JavaScopes.RUNTIME
);

如果您不在Maven插件之外:

If you're outside of Maven plugin:

File repo = new File("/tmp/local-repository");
MavenProject project = new MavenProject();
project.setRemoteProjectRepositories(
  Arrays.asList(
    new RemoteRepository(
      "maven-central",
      "default",
      "http://repo1.maven.org/maven2/"
    )
  )
);
Collection<Artifact> deps = new Aether(project, repo).resolve(
  new DefaultArtifact("junit", "junit-dep", "", "jar", "4.10"),
  "runtime"
);

您唯一需要的依赖项是:

The only dependency you need is:

<dependency>
  <groupId>com.jcabi</groupId>
  <artifactId>jcabi-aether</artifactId>
  <version>0.7.5</version>
</dependency>

这篇关于如何使用DependencyGraphBuilder以编程方式列出所有传递性依赖项,包括Maven中覆盖的传递性依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆