Retrieving Maven Artifact from Repository using Maven Java API

后端 未结 3 1450
谎友^
谎友^ 2021-01-12 05:17

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

Specif

相关标签:
3条回答
  • 2021-01-12 06:10

    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>
    
    0 讨论(0)
  • 2021-01-12 06:12

    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.

    0 讨论(0)
  • 2021-01-12 06:22

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

    0 讨论(0)
提交回复
热议问题