这是我在多模块项目中的父 pom.xml
(其中的一部分):
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
…
此配置指示mvn
在根项目和 的每个子模块中执行checkstyle
插件。我不希望它以这种方式工作。相反,我希望这个插件只对根项目执行,并跳过每个子模块。同时,我有很多子模块,我不喜欢在每个子模块中显式跳过插件执行的想法。
Checkstyle 文档 says “..确保您不在子模块中包含 Maven Checkstyle 插件..”。但是我如何确保如果我的子模块继承了我的根 pom.xml
?我迷路了,请帮忙。
最佳答案
But how can I ensure that if my sub-modules inherit my root pom.xml?
要严格回答这个问题,您可以指定一个 <inherited>
<plugin>
中的元素定义。来自POM Reference :
inherited:
true
orfalse
, whether or not this plugin configuration should apply to POMs which inherit from this one.
像这样:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<!-- Lock down plugin version for build reproducibility -->
<version>2.5</version>
<inherited>true</inherited>
<configuration>
...
</configuration>
</plugin>
一些更多的建议/评论(可能不适用):
- 您应该始终锁定插件版本以实现构建的可重复性(您可以使用 Maven Enforcer Plugin 强制执行此规则)。
- 人们通常希望使用 a Custom Checkstyle Checker Configuration和/或 a Suppressions Filter .
- Multimodule Configuration描述了一个典型的设置,允许在大型多模块项目中共享配置文件。
关于java - 如何在多模块项目中使用 Maven Checkstyle 插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3414440/