8

If I have a Maven Artifact information (GroupId, ArtifactId, Version) how can I programmatically (using Java) retrieve that Artifact from my local repository?

Specifically, I need to be able to connect to the Maven Repository and create/retrieve a org.apache.maven.artifact.Artifact so I can retrieve the file associated with the Artifact.

I have looked into m2e source code, but the MavenImpl.java (which provides Artifact resolution) is way more complex than what I need and it is difficult to understand how the connection to the repository works.

4

3 回答 3

9

你可能想看看Aether。有关示例,请参见Wiki

于 2012-07-26T19:33:39.653 回答
0

这就是我们在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
);

给它一个远程存储库列表、本地存储库的位置以及工件的 Maven 坐标。顾名思义,该库使用Sonatype 的Apache Aether

于 2012-10-28T12:37:21.837 回答
0

您可以根据给定的信息构建一个 URL 并下载文件(注意,将 替换为'.'):<groupId>'/'

<repositoryUrl>/<groupId>/<artifactId>/<version>/<artifactId>-<version>.<type>
于 2012-07-26T20:02:22.453 回答