问题描述
如何使用Aether获得MavenProject的所有依赖项(包括可传递的依赖项)?
How can you get all the dependencies of a MavenProject (including transitive ones) using Aether?
我看到了许多示例,其中指定了gav
,它可以解决工件及其所有依赖项.一切都很好.但是,如果应该从要解析其依赖项的同一项目中调用您的插件,则这似乎不起作用(或者我做错了).有人可以给我一个如何做的工作示例吗?
I have seen numerous examples where you specify the gav
and it resolves the artifact and all it's dependencies. This is all fine. However, if your plugin is supposed to be invoked from the same project whose dependencies you're trying to resolve, this does not seem to work (or perhaps I am doing it wrong). Could somebody please give me a working example of how to do it?
我用.
推荐答案
尝试使用实用程序类 Classpath
nofollow> jcabi-aether
:
Try to use an utility class Classpath
from jcabi-aether
:
Collection<File> jars = new Classpath(
this.getProject(),
new File(this.session.getLocalRepository().getBasedir()),
"test" // the scope you're interested in
);
您将获得插件所在的当前Maven项目中处于测试"范围内的JAR和目录的列表.
You will get a list of JARs and directories which are in "test" scope in the current Maven project your plugin is in.
如果您有兴趣获取 Artifact
s而不是File
s,请使用 Aether
直接类:
If you're interested to get a list of Artifact
s instead of File
s, use Aether
class directly:
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));
}
这篇关于使用Aether获取MavenProject的所有依赖项(包括可传递的依赖项)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!