1 package org.apache.maven.resolver.examples.resolver;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.List;
24
25 import org.eclipse.aether.artifact.Artifact;
26 import org.eclipse.aether.artifact.DefaultArtifact;
27 import org.eclipse.aether.deployment.DeploymentException;
28 import org.eclipse.aether.graph.DependencyNode;
29 import org.eclipse.aether.installation.InstallationException;
30 import org.eclipse.aether.resolution.DependencyResolutionException;
31 import org.eclipse.aether.util.artifact.SubArtifact;
32
33
34
35 @SuppressWarnings( "unused" )
36 public class ResolverDemo
37 {
38
39 public void resolve()
40 throws DependencyResolutionException
41 {
42 Resolver resolver = new Resolver( "http://localhost:8081/nexus/content/groups/public", "target/aether-repo" );
43
44 ResolverResult result = resolver.resolve( "com.mycompany.app", "super-app", "1.0" );
45
46
47
48 DependencyNode root = result.getRoot();
49
50
51
52 List<File> artifacts = result.getResolvedFiles();
53
54
55
56 String classpath = result.getResolvedClassPath();
57 }
58
59 public void installAndDeploy()
60 throws InstallationException, DeploymentException
61 {
62 Resolver resolver = new Resolver( "http://localhost:8081/nexus/content/groups/public", "target/aether-repo" );
63
64 Artifact artifact = new DefaultArtifact( "com.mycompany.super", "super-core", "jar", "0.1-SNAPSHOT" );
65 artifact = artifact.setFile( new File( "jar-from-whatever-process.jar" ) );
66 Artifact pom = new SubArtifact( artifact, null, "pom" );
67 pom = pom.setFile( new File( "pom-from-whatever-process.xml" ) );
68
69
70
71 resolver.install( artifact, pom );
72
73
74
75 resolver.deploy( artifact, pom, "http://localhost:8081/nexus/content/repositories/snapshots/" );
76 }
77
78 }