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 org.apache.maven.resolver.examples.util.Booter; 023import org.eclipse.aether.RepositorySystem; 024import org.eclipse.aether.RepositorySystemSession; 025import org.eclipse.aether.artifact.Artifact; 026import org.eclipse.aether.artifact.DefaultArtifact; 027import org.eclipse.aether.graph.Dependency; 028import org.eclipse.aether.resolution.ArtifactDescriptorRequest; 029import org.eclipse.aether.resolution.ArtifactDescriptorResult; 030 031/** 032 * Determines the direct dependencies of an artifact as declared in its artifact descriptor (POM). 033 */ 034public class GetDirectDependencies 035{ 036 037 /** 038 * Main. 039 * @param args 040 * @throws Exception 041 */ 042 public static void main( String[] args ) 043 throws Exception 044 { 045 System.out.println( "------------------------------------------------------------" ); 046 System.out.println( GetDirectDependencies.class.getSimpleName() ); 047 048 RepositorySystem system = Booter.newRepositorySystem(); 049 050 RepositorySystemSession session = Booter.newRepositorySystemSession( system ); 051 052 Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-impl:1.0.0.v20140518" ); 053 054 ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest(); 055 descriptorRequest.setArtifact( artifact ); 056 descriptorRequest.setRepositories( Booter.newRepositories( system, session ) ); 057 058 ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor( session, descriptorRequest ); 059 060 for ( Dependency dependency : descriptorResult.getDependencies() ) 061 { 062 System.out.println( dependency ); 063 } 064 } 065 066}