For the Maven 3 plugin, which is the last way to solve the artifact

What is the last way to enable Artifact in the Maven 3.2.5 plugin. ArtifactResolver and ArtifactFactory (depreciated) are in the mapping library, which implies that there is a newer / better way of resolution, but I can not find examples, documents or search queries that do not use above.

thank

Michael

+4
source share
1 answer

There is a sonatip blog:

http://blog.sonatype.com/2011/01/how-to-use-aether-in-maven-plugins

This is the code from the blog post (all details are described in detail here):

public MyMojo extends AbstractMojo {

    /**
     * The entry point to Aether, i.e. the component doing all the work.
     */
    @Component
    private RepositorySystem repoSystem;

    /**
     * The current repository/network configuration of Maven.
     */
    @Parameter(defaultValue = "${repositorySystemSession}", readonly = true)
    private RepositorySystemSession repoSession;

    /**
     * The project remote repositories to use for the resolution of plugins and their dependencies.
     */
    @Parameter(defaultValue = "${project.remotePluginRepositories}", readonly = true)
    private List<RemoteRepository> remoteRepos;

    public void execute() throws MojoExecutionException, MojoFailureException {
        ArtifactRequest request = new ArtifactRequest();
        request.setArtifact(new DefaultArtifact( "org.apache.maven:maven-model:3.0" ) );
        request.setRepositories( remoteRepos );

        ArtifactResult result = repoSystem.resolveArtifact( repoSession, request );
    } 

}

result.getArtifact(), result.getArtifact().getFile(), , .

+3

All Articles