我正在尝试使用以太来获取maven工件的依赖关系。我看到一个RepositorySystem.collectDependencies(),但它只获取编译和运行时范围的依赖项。如何获取工件的所有依赖项,包括test和provided?
答案 0 :(得分:3)
看看jcabi-aether(我是开发人员),它是Sonatype Aether的包装器:
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
);
答案 1 :(得分:2)
假设您使用DefaultRepositorySystemSession
,您可以执行以下操作:
defaultRepositorySystemSession.setDependencySelector(new DependencySelector() {
@Override
public boolean selectDependency(Dependency dependency) {
return true;
}
@Override
public DependencySelector deriveChildSelector(DependencyCollectionContext context) {
return this;
}
});
然后
CollectResult result = repositorySystem.collectDependencies(defaultRepositorySystemSession, request);
答案 2 :(得分:1)
这三个文件:
使用Aether是一个独立的工作示例。
它工作了几个月然后我突然出现了一个问题,有时在Mac JRE上会在com.sun:tools.jar上抛出DependencyResolutionException。
祝你好运,如果你决定使用它,我会转而使用maven-dependency-plugindependency:build-classpath
。
答案 3 :(得分:1)
您可以在Eclipses Aether中使用DependencyFilter
。下面的示例complete version可以在这个令人敬畏的Aether snippets.
DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE, JavaScopes.PROVIDED);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot( new Dependency( artifact, JavaScopes.COMPILE ) );
collectRequest.setRepositories(repositories);
DependencyRequest dependencyRequest = new DependencyRequest( collectRequest, classpathFilter );
List<ArtifactResult> artifactResults =
system.resolveDependencies( session, dependencyRequest ).getArtifactResults();
<强>更新强>
版本0.9.0M3与Maven 3.1.0不兼容,所以不要在Maven中使用它,即在插件中使用它。
答案 4 :(得分:1)
Take a look at this github project: https://github.com/Gemba/mvn-dd
It downloads all dependencies including test and provided.
It uses aether's library to fetch them.