What is the latest way of resolving an Artifact within a Maven 3.2.5 plugin. ArtifactResolver and ArtifactFactory(depreciated) are in the compat library which implies that there is a newer/better way of resolution, but I can not find any examples, docs or searches that do not use the above.
Thanks
Michael
Description: Goal that resolves the project dependencies from the repository. When using this goal while running on Java 9 the module names will be visible as well.
Usage of a Maven Plugin xml you can use the shorthand notation to execute the plugin: mvn <prefix>:<goal> , commonly the “prefix” is the artifact ID minus the “-maven-plugin”. For example mvn example:version .
From Maven documentation: pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one.
There's a blog from sonatype on exactly this:
http://blog.sonatype.com/2011/01/how-to-use-aether-in-maven-plugins
This is the code from the blog entry (full details are obviously described there):
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's 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 );
}
}
You can then use result.getArtifact()
to get the artifact and result.getArtifact().getFile()
to get the file of the artifact if you need it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With