Search in sources :

Example 6 with DependencyRequest

use of org.sonatype.aether.resolution.DependencyRequest in project sonatype-aether by sonatype.

the class ResolveTransitiveDependencies method main.

public static void main(String[] args) throws Exception {
    System.out.println("------------------------------------------------------------");
    System.out.println(ResolveTransitiveDependencies.class.getSimpleName());
    RepositorySystem system = Booter.newRepositorySystem();
    RepositorySystemSession session = Booter.newRepositorySystemSession(system);
    Artifact artifact = new DefaultArtifact("org.sonatype.aether:aether-impl:1.9");
    RemoteRepository repo = Booter.newCentralRepository();
    DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
    collectRequest.addRepository(repo);
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter);
    List<ArtifactResult> artifactResults = system.resolveDependencies(session, dependencyRequest).getArtifactResults();
    for (ArtifactResult artifactResult : artifactResults) {
        System.out.println(artifactResult.getArtifact() + " resolved to " + artifactResult.getArtifact().getFile());
    }
}
Also used : RepositorySystem(org.sonatype.aether.RepositorySystem) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) DependencyFilter(org.sonatype.aether.graph.DependencyFilter) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult)

Example 7 with DependencyRequest

use of org.sonatype.aether.resolution.DependencyRequest in project sonatype-aether by sonatype.

the class Aether method resolve.

public AetherResult resolve(String groupId, String artifactId, String version) throws DependencyResolutionException {
    RepositorySystemSession session = newSession();
    Dependency dependency = new Dependency(new DefaultArtifact(groupId, artifactId, "", "jar", version), "runtime");
    RemoteRepository central = new RemoteRepository("central", "default", remoteRepository);
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(dependency);
    collectRequest.addRepository(central);
    DependencyRequest dependencyRequest = new DependencyRequest();
    dependencyRequest.setCollectRequest(collectRequest);
    DependencyNode rootNode = repositorySystem.resolveDependencies(session, dependencyRequest).getRoot();
    StringBuilder dump = new StringBuilder();
    displayTree(rootNode, dump);
    PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
    rootNode.accept(nlg);
    return new AetherResult(rootNode, nlg.getFiles(), nlg.getClassPath());
}
Also used : MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) DependencyNode(org.sonatype.aether.graph.DependencyNode) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) PreorderNodeListGenerator(org.sonatype.aether.util.graph.PreorderNodeListGenerator) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Aggregations

CollectRequest (org.sonatype.aether.collection.CollectRequest)7 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)7 DependencyRequest (org.sonatype.aether.resolution.DependencyRequest)7 DependencyFilter (org.sonatype.aether.graph.DependencyFilter)6 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)6 Artifact (org.sonatype.aether.artifact.Artifact)5 Dependency (org.sonatype.aether.graph.Dependency)4 PatternExclusionsDependencyFilter (org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter)4 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)2 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)1 Repository (org.apache.zeppelin.dep.Repository)1 RepositoryException (org.sonatype.aether.RepositoryException)1 RepositorySystem (org.sonatype.aether.RepositorySystem)1 DependencyNode (org.sonatype.aether.graph.DependencyNode)1 Authentication (org.sonatype.aether.repository.Authentication)1 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)1 PreorderNodeListGenerator (org.sonatype.aether.util.graph.PreorderNodeListGenerator)1