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

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

问题描述

我有一个 maven 多模块项目(男孩,我在这个网站上写了太多次方式).几乎所有的模块(即那些包含代码的模块)都应该运行 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 继承,以便不需要插件的模块有一个父级,而需要插件的模块有不同的父级.如果您不想这样做,那么您可以在子模块中将执行阶段显式设置为无".例如.如果您有这样的父 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天全站免登陆