Skip to content

Instantly share code, notes, and snippets.

@jirkapenzes
Created January 4, 2018 11:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jirkapenzes/44b27a6daf6e5b8dda887fee5a58d0f1 to your computer and use it in GitHub Desktop.
Save jirkapenzes/44b27a6daf6e5b8dda887fee5a58d0f1 to your computer and use it in GitHub Desktop.
Aether aether = Aether.builder()
.setLocalRepo(temp.newFolder().getPath())
.addRemoteRepo("maven-central", "http://repo1.maven.org/maven2").build();
List<Artifact> dependencies = aether.resolveDependencies(new DefaultArtifact("org.elasticsearch:elasticsearch:5.5.2"));
List<URL> urls = new ArrayList<>();
for (Artifact artifact : dependencies) {
URL url = new URL(new URL("file:"), artifact.getFile().getAbsolutePath());
urls.add(url);
}
ClassLoader classLoader = URLClassLoader.newInstance(urls.toArray(new URL[0]), classLoader);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment