1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.resolver.examples.resolver;
20
21 import java.io.File;
22 import java.util.List;
23
24 import org.apache.maven.resolver.examples.util.Booter;
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 public static void main(String[] args) throws Exception {
38 System.out.println("------------------------------------------------------------");
39 System.out.println(ResolverDemo.class.getSimpleName());
40
41 Resolver resolver =
42 new Resolver(Booter.selectFactory(args), "https://repo.maven.apache.org/maven2/", "target/aether-repo");
43 ResolverResult result = resolver.resolve("junit", "junit", "4.13.2");
44
45 System.out.println("Result:");
46 System.out.println("classpath=" + result.getResolvedClassPath());
47 System.out.println("files=" + result.getResolvedFiles());
48 System.out.println("root=" + result.getRoot());
49 }
50
51 public void resolve(final String factory) throws DependencyResolutionException {
52 Resolver resolver =
53 new Resolver(factory, "http://localhost:8081/nexus/content/groups/public", "target/aether-repo");
54
55 ResolverResult result = resolver.resolve("com.mycompany.app", "super-app", "1.0");
56
57
58
59 DependencyNode root = result.getRoot();
60
61
62
63 List<File> artifacts = result.getResolvedFiles();
64
65
66
67 String classpath = result.getResolvedClassPath();
68 }
69
70 public void installAndDeploy(final String factory) throws InstallationException, DeploymentException {
71 Resolver resolver =
72 new Resolver(factory, "http://localhost:8081/nexus/content/groups/public", "target/aether-repo");
73
74 Artifact artifact = new DefaultArtifact("com.mycompany.super", "super-core", "jar", "0.1-SNAPSHOT");
75 artifact = artifact.setFile(new File("jar-from-whatever-process.jar"));
76 Artifact pom = new SubArtifact(artifact, null, "pom");
77 pom = pom.setFile(new File("pom-from-whatever-process.xml"));
78
79
80
81 resolver.install(artifact, pom);
82
83
84
85 resolver.deploy(artifact, pom, "http://localhost:8081/nexus/content/repositories/snapshots/");
86 }
87 }