Retrieving Maven Artifact from Repository using Maven Java API

davdic picture davdic · Jul 26, 2012 · Viewed 7.3k times · Source

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.

Answer

Philippe Marschall picture Philippe Marschall · Jul 26, 2012

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