在单module的项目中, 使用maven的checkstyle/findbugs/pmd等插件的方式与前文所述,现在来说下, 在多module的项目中的使用方法。
参考:https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/multi-module-config.html
1. 添加一个新的module 叫build-tools,目录结构可以自定义。类似:src/main/resouces/checkstyle.xml
2.为build-tools添加pom.xml文件如:
3. 在项目最外层的pom.xml文件中,添加对build-tools的依赖。
1)在<modules>下添加 <module>build-tools</module>,一定要放在最前面,否则会出现去maven 仓库下载build-tools-1.0.jar,而无法找到,导致失败。
2)在<build><plugins>添加checkstyle/pmd/findbugs等的依赖。如:
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>3.6</version> <configuration> <rulesets> <ruleset>../build-tools/src/main/resources/pmd_rules.xml</ruleset> </rulesets> </configuration> <dependencies> <dependency> <groupId>com.example.test</groupId> <artifactId>build-tools</artifactId> <version>1.0</version> </dependency> </dependencies> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <version>3.0.3</version> <configuration> <excludeFilterFile>build-tools/src/main/resources/findbugs_exclude.xml</excludeFilterFile> </configuration> <dependencies> <dependency> <groupId>com.example.test</groupId> <artifactId>build-tools</artifactId> <version>1.0</version> </dependency> </dependencies> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>2.17</version> <configuration> <configLocation>build-tools/src/main/resources/checkstyle_rules.xml</configLocation> <failsOnError>false</failsOnError> <linkXRef>false</linkXRef> </configuration> <dependencies> <dependency> <groupId>com.example.test</groupId> <artifactId>build-tools</artifactId> <version>1.0</version> </dependency> </dependencies> </plugin>
4. 运行mvn compile checkstyle:checkstyle等命令即可生成相关的报告结果,位置在各个module的target目录下。