从 2.12 版开始,可以直接在pom.xml中插件本身的配置部分定义内联检查器配置。
当每次编译都应该执行 Checkstyle 检查并且您不喜欢为您的 Checkstyle 规则创建自己的项目并且不喜欢拥有单独的父 POM 结构时,这尤其有用。
要在pom.xml中定义自定义 Checkstyle 检查器配置,请使用checkstyleRules参数。
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.15</version>
<executions>
<execution>
<id>verify-style</id>
<phase>process-classes</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<logViolationsToConsole>true</logViolationsToConsole>
<checkstyleRules>
<module name="Checker">
<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
<module name="FileLength">
<property name="max" value="3500" />
<property name="fileExtensions" value="java"/>
</module>
<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="FileTabCharacter"/>
<module name="TreeWalker">
<module name="StaticVariableName"/>
<module name="TypeName">
<property name="format" value="^_?[A-Z][a-zA-Z0-9]*$"/>
</module>
</module>
</module>
</checkstyleRules>
</configuration>
</plugin>
</plugins>
</build>
...
</project>