在Maven多模块项目中,如何在一个孩子中禁用插件? [英] In a Maven multi-module project, how can I disable a plugin in one child?

查看:139
本文介绍了在Maven多模块项目中,如何在一个孩子中禁用插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Maven多模块项目(男孩,我在此站点上多次写过 way 的开头).几乎所有模块(即其中包含 code 的模块)都应运行maven-site-plugin生成有关代码覆盖率的报告等.这些模块具有详细的共享配置-该报告运行,某些插件要覆盖/排除哪些文件,等等.

I have a maven multi-module project (boy, I've written that opening way too many times on this site). Almost all the modules (that is, the ones that have code in them) should run the maven-site-plugin to generate reports about code coverage, etc. These have a detailed shared configuration -- which reports to run, which files to cover/exclude for certain plugins, etc.

但是,有一些处理打包的模块-运行程序集插件以生成tarball等.这些从运行站点报告中得不到任何好处-没有要分析的代码,也没有要报告的测试.

However, there are a few modules that deal with packaging -- running the assembly plugin to generate a tarball, etc. These gain nothing from running a site report -- there's no code to analyze, no tests to report on.

因此,我有很多模块需要共享插件配置,还有一些模块需要不运行插件,最好是完全没有.如果将插件放在父POM的<build>部分中,则可以执行前一个(共享配置),但是在这种情况下,我似乎无法关闭插件.如果我将配置下推到每个模块自己的POM,则可以使用后者(避免运行插件),但是在这种情况下,我找不到能共享配置信息的好方法.

So I have a lot of modules that need to share plugin configuration, and a few modules that need to not run the plugin, preferably at all. I can do the former (share configuration) if I put the plugin in the <build> section of the parent POM, but I can't seem to turn off the plugin when I need to in this case. I can do the latter (avoid running the plugin) if I push configuration down to each module's own POM, but I can't figure out a good way to share the configuration information in this case.

我想要的是-共享配置,对于有时被子模块禁用的插件-甚至可能吗?如果可以,怎么办?

Is what I want -- shared configuration, for a plugin that's sometimes disabled by a child module -- even possible? If so, how?

推荐答案

通过运行插件",我假设您的意思是该插件已绑定到生命周期阶段,并且您希望将其解除绑定模块.首先,您可以考虑更改POM继承,以便不需要插件的模块具有一个父级,而确实具有不同父级的模块.如果您不想这样做,则可以在子模块中将执行阶段显式设置为"nothing".例如.如果您有这样的父pom配置:

By "run the plugin", I'm assuming you mean that the plugin is bound to a lifecycle phase, and you'd like to unbind it in some modules. First, you could consider changing your POM inheritance so that the modules that don't need the plugins have one parent and the ones that do have a different parent. If you don't want to do that, then you can explicitly set the execution phase to "nothing" in a child module. E.g. if you had a parent pom configuration like this:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>i-do-something</id>
            <phase>initialize</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                ... lots of configuration
            </configuration>
        </execution>
    </executions>
</plugin>

然后在子模块中,您可以执行以下操作:

Then in a child module, you could do this:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>i-do-something</id>
            <phase/>
        </execution>
    </executions>
</plugin>

因为它是相同的插件和相同的执行ID,所以它会覆盖父级中指定的配置,现在该插件未绑定到子项目中的某个阶段.

Because it's the same plugin and the same execution id, it overrides the configuration specified in the parent, and now the plugin isn't bound to a phase in the child project.

这篇关于在Maven多模块项目中,如何在一个孩子中禁用插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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