How to determine what artifacts are built from a maven reactor plan (ie: including sub modules)?

心不动则不痛 提交于 2019-12-21 20:35:15

问题


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

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.


回答1:


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.

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.

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

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);
        }
    }
}


来源:https://stackoverflow.com/questions/10454181/how-to-determine-what-artifacts-are-built-from-a-maven-reactor-plan-ie-includi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!