以下示例描述了 Checkstyle 插件的基本用法。
要生成 Checkstyle 报告作为项目报告的一部分,请在pom.xml的<reporting> 部分添加 Checkstyle 插件 。
<project> ... <reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> </plugin> </plugins> </reporting> ... </project>
然后,执行站点插件以生成报告。
mvn site
您还可以通过 从命令行显式执行checkstyle:checkstyle目标来生成 Checkstyle 报告。 除非您想使用特定配置,否则不需要在pom.xml中指定 Checkstyle 插件。
mvn checkstyle:checkstyle
要专门配置 Checkstyle 插件,您需要将其添加到pom.xml的<build> 部分, 如下面的示例所示。
<project> ... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <configuration> <enableRulesSummary>false</enableRulesSummary> ... </configuration> </plugin> </plugins> </build> ... </project>