1

如何使用 Aether 获取 MavenProject 的所有依赖项(包括传递的依赖项)?

我见过很多例子,你指定了gav它,它解决了工件及其所有依赖项。这一切都很好。但是,如果您的插件应该从您试图解决其依赖项的同一个项目中调用,这似乎不起作用(或者也许我做错了)。有人可以给我一个如何做到这一点的工作示例吗?

我已经尝试了这个 SO post中显示的 jcabi-aether 示例。

4

1 回答 1

1

尝试使用以下实用程序类Classpathjcabi-aether

Collection<File> jars = new Classpath(
  this.getProject(),
  new File(this.session.getLocalRepository().getBasedir()),
  "test" // the scope you're interested in
);

您将获得插件所在的当前 Maven 项目中“测试”范围内的 JAR 和目录列表。

如果您有兴趣获取Artifacts 而不是Files 的列表,请直接使用Aetherclass:

Aether aether = new Aether(this.getProject(), repo);
Set<Artifact> artifacts = new HashSet<Artifact>();
for (Artifact dep : this.getProject().getDependencyArtifacts()) {
  artifacts.addAll(aether.resolve(dep, JavaScopes.COMPILE));
}
于 2013-05-21T10:31:58.137 回答