在 Maven 3.2.5 插件中解决 Artifact 的最新方法是什么。 ArtifactResolver 和 ArtifactFactory(depreciated) 在 compat 库中,这意味着有更新/更好的解决方法,但我找不到任何不使用上述内容的示例、文档或搜索。
谢谢
迈克尔
最佳答案
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()
如果需要,可以获取 Artifact 的文件。
关于maven - 对于 Maven 3 插件,解决 Artifact 的最新方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28361289/