mvn plugin checkstyle/findbugs/pmd在多module项目中的使用

在单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文件如:

  1. <project>
  2. <modelVersion>4.0.0</modelVersion>
  3. <groupId>com.example.test</groupId>
  4. <artifactId>build-tools</artifactId>
  5. <version>1.0</version>
  6. <name>Build Tools</name>
  7. </project>

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目录下。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值