Retrieving Maven Artifact from Repository using Maven Java API

风流意气都作罢 提交于 2019-12-01 04:46:13
Philippe Marschall

You'll probably want to look at Aether. See the Wiki for examples.

You can construct a URL from the given information and download the file (note, replace the '.' in the <groupId> with '/'):

<repositoryUrl>/<groupId>/<artifactId>/<version>/<artifactId>-<version>.<type>

This is how we do it in jcabi-aether:

final File repo = this.session.getLocalRepository().getBasedir();
final Collection<Artifact> deps = new Aether(this.getProject(), repo).resolve(
  new DefaultArtifact("junit", "junit-dep", "", "jar", "4.10"),
  JavaScopes.RUNTIME
);

Give it a list of remote repositories, a location of a local repo, and Maven coordinates of the artifact. As the name shows, the library uses Apache Aether from Sonatype.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!