我正在使用Aether来解决java项目中maven工件的依赖关系。我想找到直接依赖(没有传递)并希望它们作为单个已解析的工件。
如果使用shrinkwrap,我会做类似
的事情Resolver.resolve(mavenArtifact).withoutTransitivity().asSingleResolvedArtifact();
我有以下内容可以找到没有传递性的家属
RepositorySystem repoSystem = newRepositorySystem();
RepositorySystemSession session = newSession( repoSystem );
Artifact artifact = new DefaultArtifact(serviceJar.getCoordinate() );
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
descriptorRequest.setArtifact( artifact );
descriptorRequest.setRepositories(new ArrayList<RemoteRepository>( Arrays.asList( newCentralRepository() ) ));
ArtifactDescriptorResult descriptorResult = repoSystem.readArtifactDescriptor( session, descriptorRequest );
descriptorResult.getDependencies();
}
private static RepositorySystem newRepositorySystem()
{
DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
locator.addService( RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class );
locator.addService( TransporterFactory.class, FileTransporterFactory.class );
locator.addService( TransporterFactory.class, HttpTransporterFactory.class );
return locator.getService( RepositorySystem.class );
}
private static RepositorySystemSession newSession( RepositorySystem system )
{
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
LocalRepository localRepo = new LocalRepository( "/tmp" );
session.setLocalRepositoryManager( system.newLocalRepositoryManager( session, localRepo ));
return session;
}
public static List<RemoteRepository> newRepositories( RepositorySystem system, RepositorySystemSession session )
{
return new ArrayList<RemoteRepository>( Arrays.asList( newCentralRepository() ) );
}
private static RemoteRepository newCentralRepository()
{
return new RemoteRepository.Builder( "central", "default", "http://central-repo/" ).build();
}
所以这给了我一个所有依赖项的列表。我怎样才能获得这些依赖项的单个jar? 如何使用Aether实现这一目标? 是否有关于这两个库如何彼此不同的文档?换句话说,在Aether中等同于'MavenResolvedartifact'(如在shrinkwrap中)?那么我可以使用原始java将其转换为单个jar吗?