Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Aether/Resolving Dependencies"
(Added page about resolving deps) |
m |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
− | |||
Extending the code snippets from {{AetherLink|Setting Aether Up}} and {{AetherLink|Creating a Repository System Session}}, the snippet below demonstrates how to actually resolve the transitive dependencies of say <tt>org.apache.maven:maven-profile:2.2.1</tt> and to dump the result as a class path to the console: | Extending the code snippets from {{AetherLink|Setting Aether Up}} and {{AetherLink|Creating a Repository System Session}}, the snippet below demonstrates how to actually resolve the transitive dependencies of say <tt>org.apache.maven:maven-profile:2.2.1</tt> and to dump the result as a class path to the console: | ||
Line 14: | Line 11: | ||
Dependency dependency = | Dependency dependency = | ||
new Dependency( new DefaultArtifact( "org.apache.maven:maven-profile:2.2.1" ), "compile" ); | new Dependency( new DefaultArtifact( "org.apache.maven:maven-profile:2.2.1" ), "compile" ); | ||
− | RemoteRepository central = new RemoteRepository( "central", "default", "http://repo1.maven.org/maven2/" ); | + | RemoteRepository central = new RemoteRepository.Builder( "central", "default", "http://repo1.maven.org/maven2/" ).build(); |
CollectRequest collectRequest = new CollectRequest(); | CollectRequest collectRequest = new CollectRequest(); | ||
Line 21: | Line 18: | ||
DependencyNode node = repoSystem.collectDependencies( session, collectRequest ).getRoot(); | DependencyNode node = repoSystem.collectDependencies( session, collectRequest ).getRoot(); | ||
− | DependencyRequest dependencyRequest = new DependencyRequest( node | + | DependencyRequest dependencyRequest = new DependencyRequest(); |
+ | dependencyRequest.setRoot( node ); | ||
repoSystem.resolveDependencies( session, dependencyRequest ); | repoSystem.resolveDependencies( session, dependencyRequest ); | ||
Line 36: | Line 34: | ||
To learn about how you can control the calculation of transitive dependencies, please see the article about {{AetherLink|Transitive Dependency Resolution}}. | To learn about how you can control the calculation of transitive dependencies, please see the article about {{AetherLink|Transitive Dependency Resolution}}. | ||
+ | |||
+ | [[Category:Aether]] |
Latest revision as of 01:42, 10 July 2014
Extending the code snippets from Setting Aether Up and Creating a Repository System Session, the snippet below demonstrates how to actually resolve the transitive dependencies of say org.apache.maven:maven-profile:2.2.1 and to dump the result as a class path to the console:
public static void main( String[] args ) throws Exception { RepositorySystem repoSystem = newRepositorySystem(); RepositorySystemSession session = newSession( repoSystem ); Dependency dependency = new Dependency( new DefaultArtifact( "org.apache.maven:maven-profile:2.2.1" ), "compile" ); RemoteRepository central = new RemoteRepository.Builder( "central", "default", "http://repo1.maven.org/maven2/" ).build(); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot( dependency ); collectRequest.addRepository( central ); DependencyNode node = repoSystem.collectDependencies( session, collectRequest ).getRoot(); DependencyRequest dependencyRequest = new DependencyRequest(); dependencyRequest.setRoot( node ); repoSystem.resolveDependencies( session, dependencyRequest ); PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); node.accept( nlg ); System.out.println( nlg.getClassPath() ); }
So once you have initialized the repository system and created a session, the general pattern is to create some request object, call its setters to configure the request, do the operation and evaluate the result object.
Since "all theory is grey", we maintain some runnable examples among our sources. These examples provide a more extensive demonstration of Aether and its use, so what are you waiting for?
To learn about how you can control the calculation of transitive dependencies, please see the article about Transitive Dependency Resolution.