我有一个 maven 项目,我正在尝试使用 Artifact resolver API 获取直接依赖的所有传递依赖。如何以编程方式实现这一点?
我可以使用 aether-1.1.0 获得相同的功能。但是我们需要迁移到 Maven Artifact Resolver{ https://maven.apache.org/resolver/index.html }。我尝试了一些类似下面的东西,
@Component
private org.apache.maven.repository.RepositorySystem repoSystem;
..
ArtifactRepository artifactRepo = new MavenArtifactRepository();
org.apache.maven.repository.Proxy mavenProxy = new org.apache.maven.repository.Proxy();
mavenProxy.setHost(proxyDetails.getHost());
mavenProxy.setPort(proxyDetails.getPort());
Artifact sourcesArtifact = repoSystem.createArtifact(rootGroupId, rootArtifact, rootVersion, JavaScopes.COMPILE,"jar");
sourcesArtifact.setRepository(artifactRepo);
ArtifactResolutionRequest request2 = new ArtifactResolutionRequest().setArtifact(sourcesArtifact);
ArtifactResolutionResult depResult =repoSystem.resolve(request2);
result2.getArtifacts().forEach(dep5 -> {
System.out.println(dep5.getId());
....}
但它没有在这里打印任何传递依赖项
预期结果是:我需要给定直接依赖项的传递依赖项列表。