如何确定从Maven反应堆计划中构建了哪些工件(即:包括子模块)? [英] How to determine what artifacts are built from a maven reactor plan (ie: including sub modules)?

查看:69
本文介绍了如何确定从Maven反应堆计划中构建了哪些工件(即:包括子模块)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(注意:该问题最初由Dan Allen在Google+上的此处提出: https://plus .google.com/114112334290393746697/posts/G6BLNgjyqeQ )

(Note: this question was originally posed by Dan Allen on Google+ here: https://plus.google.com/114112334290393746697/posts/G6BLNgjyqeQ)

如果我运行了"mvn install",它将安装哪些工件?或者,如果我运行了"mvn deploy",它将部署什么工件?

If I ran 'mvn install', what artifacts would it install? Or, if I ran 'mvn deploy', what artifacts would it deploy?

这可能是一个非常简单易写的插件,但是如果它已经可以通过编程方式使用,我不想重新发明它.似乎应该可以在某个地方使用它.

This would likely be a fairly straightforward plugin to write, but I don't want to re-invent this if it's already available somewhere programmatically. It seems like this should be readily available somewhere.

推荐答案

由于 Andrew Logvinov 已发表评论,任何Maven插件可以附加 其他工件.所以我认为如果没有实际的话这是不可能的 构建项目并执行与生命周期阶段绑定的所有插件,直到package.

As Andrew Logvinov already commented, any maven plugin could attach additional artifacts. So I don't think this would be possible without actually building the project and executing all plugins bound to lifecycle phases upto package.

我不知道有任何先前存在的插件正在执行此操作,因此关闭可能 将实际部署运行到临时目录中,然后列出 包含的文件.为了避免在执行此操作时修改本地存储库,您可以 想要避免install阶段. verify阶段直接发生 在install之前,可以显式调用deploy mojo.

I don't know of any preexisting plugins doing this, the closes would probably be to run an actual deploy into a temporary directory and then list the contained files. To avoid modifying your local repository while doing this, you would want to avoid the install phase. The verify phase happens directly before install, the deploy mojo can then be invoked explicitly.

部署插件允许指定一个使用这样的文件url的备用存储库:

The deploy plugin allows to specify an alternative repository using a file url like this:

mvn verify deploy:deploy -DaltDeploymentRepository=snapshots::default::file:///home/jh/Temp/repository

列出所有附加工件的maven插件的最简单实现如下所示:

The simplest implementation of a maven plugin listing all attached artifacts could look like this:

/**
 * @goal list-artifacts
 * @phase verify
 */
public class ListArtifactsMojo extends AbstractMojo {

    /**
     * @parameter default-value="${project}"
     * @required
     * @readonly
     */
    MavenProject project;

    public void execute() throws MojoExecutionException, MojoFailureException {
        Collection<Artifact> artifacts = new ArrayList<Artifact>();
        artifacts.add(project.getArtifact());
        artifacts.addAll(project.getAttachedArtifacts());

        for (Artifact artifact : artifacts) {
            System.out.println("Artifact: " + artifact);
        }
    }
}

这篇关于如何确定从Maven反应堆计划中构建了哪些工件(即:包括子模块)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆