maven - 对于 Maven 3 插件,解决 Artifact 的最新方法是什么

标签 maven maven-3 maven-plugin

在 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/

相关文章:

maven-plugin - 使用 Maven 插件将多个(js)文件聚合/组装成一个(js)文件而不压缩的最简单方法是什么?

maven-2 - 如何用 JUnit 4 写一些东西到万无一失的日志

maven - 如何在settings.xml中定义maven系统属性?

windows - linux下maven-jetty-plugin无法绑定(bind)地址

java - 有没有办法从命令行配置 Maven POM 的版本?

java - Maven 插件 Mojo 配置默认参数值

java - Maven 更新项目后项目结构发生了变化,源文件夹的包含和排除模式也发生了变化

mongodb - 无法生成 querydsl Q 类

java - 如何使用 Maven 创建没有依赖项的可执行 jar?

java - spring boot maven插件-jvm参数-直接内存大小设置