在Maven 3.2.5插件中解决工件的最新方法是什么。ArtifactResolver和ArtifactFactory(已折旧)在compat库中,这意味着有一种更新/更好的解决方法,但我找不到任何不使用上述方法的示例、文档或搜索。
感谢
Michael
Sonateype有一个博客正是关于这个:
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()
获取工件的文件。