001package org.apache.maven.resolver.examples; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.List; 023 024import org.apache.maven.resolver.examples.util.Booter; 025import org.eclipse.aether.RepositorySystem; 026import org.eclipse.aether.RepositorySystemSession; 027import org.eclipse.aether.artifact.Artifact; 028import org.eclipse.aether.artifact.DefaultArtifact; 029import org.eclipse.aether.collection.CollectRequest; 030import org.eclipse.aether.graph.Dependency; 031import org.eclipse.aether.graph.DependencyFilter; 032import org.eclipse.aether.resolution.ArtifactResult; 033import org.eclipse.aether.resolution.DependencyRequest; 034import org.eclipse.aether.util.artifact.JavaScopes; 035import org.eclipse.aether.util.filter.DependencyFilterUtils; 036 037/** 038 * Resolves the transitive (compile) dependencies of an artifact. 039 */ 040public class ResolveTransitiveDependencies 041{ 042 043 /** 044 * Main. 045 * @param args 046 * @throws Exception 047 */ 048 public static void main( String[] args ) 049 throws Exception 050 { 051 System.out.println( "------------------------------------------------------------" ); 052 System.out.println( ResolveTransitiveDependencies.class.getSimpleName() ); 053 054 RepositorySystem system = Booter.newRepositorySystem( Booter.selectFactory( args ) ); 055 056 RepositorySystemSession session = Booter.newRepositorySystemSession( system ); 057 058 Artifact artifact = new DefaultArtifact( "org.apache.maven.resolver:maven-resolver-impl:1.3.3" ); 059 060 DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter( JavaScopes.COMPILE ); 061 062 CollectRequest collectRequest = new CollectRequest(); 063 collectRequest.setRoot( new Dependency( artifact, JavaScopes.COMPILE ) ); 064 collectRequest.setRepositories( Booter.newRepositories( system, session ) ); 065 066 DependencyRequest dependencyRequest = new DependencyRequest( collectRequest, classpathFlter ); 067 068 List<ArtifactResult> artifactResults = 069 system.resolveDependencies( session, dependencyRequest ).getArtifactResults(); 070 071 for ( ArtifactResult artifactResult : artifactResults ) 072 { 073 System.out.println( artifactResult.getArtifact() + " resolved to " 074 + artifactResult.getArtifact().getFile() ); 075 } 076 } 077 078}