在Maven 3.2.5插件中解析工件的最新方法是什么? ArtifactResolver和ArtifactFactory(折旧)位于compat库中,这意味着有更新/更好的解决方法,但我找不到任何不使用上述内容的示例,文档或搜索。
由于
迈克尔
答案 0 :(得分:3)
这是一个来自sonatype的博客:
http://blog.sonatype.com/2011/01/how-to-use-aether-in-maven-plugins
这是博客条目中的代码(显然有详细说明):
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 );
}
}
然后,您可以使用result.getArtifact()
来获取工件,并result.getArtifact().getFile()
获取工件的文件(如果需要)。