I am trying to resolve direct dependencies for a project, basically the run time and compile time dependencies in its POM and also the transitives. For this I have the following code
public class GetDirectDependencies
{
public static void main( String[] args )
throws Exception
{
System.out.println( "------------------------------------------------------------" );
System.out.println( GetDirectDependencies.class.getSimpleName() );
RepositorySystem system = Booter.newRepositorySystem();
RepositorySystemSession session = Booter.newRepositorySystemSession( system );
Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-impl:1.0.0.v20140518" );
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
descriptorRequest.setArtifact( artifact );
descriptorRequest.setRepositories( Booter.newRepositories( system, session ) );
ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor( session, descriptorRequest );
for ( Dependency dependency : descriptorResult.getDependencies() )
{
System.out.println( dependency );
}
}
}
This works correctly but how do I get a 'resolved ' list of dependencies. I need to be able to download this resolved artifact in my local repo. Basically I need a List to return from which I can get to the jar on the local disk.
If you need the jar file and the physical path to that jar you should 'resolve' it. I achieved it in the following way :
Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-util:1.0.0.v20140518" );
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact( artifact );
artifactRequest.setRepositories( Booter.newRepositories( system, session ) );
ArtifactResult artifactResult = system.resolveArtifact( session, artifactRequest );
artifact = artifactResult.getArtifact();
To get the file:
artifact.getFile();