Maven项目添加FindBugs、PMD插件

1、pom.xml添加插件版本参数

   <properties>  
          <!--其他参数-->
                ...

        <!--插件版本-->
        <pmd.version>3.8</pmd.version>
        <findbugs.version>3.0.5</findbugs.version>
    </properties>

2、添加build插件

    <build>
        <plugins>  
                    <!--其他插件-->
                        ...
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <version>${findbugs.version}</version>

                <!--在compile后自动执行check,必须事先compile编译过,不然findbugs不能发现bug-->
                <!--<executions>-->
                    <!--<execution>-->
                        <!--<id>findbugs-check</id>-->
                        <!--<phase>compile</phase>-->
                        <!--<goals>-->
                            <!--<goal>check</goal>-->
                        <!--</goals>-->
                    <!--</execution>-->
                <!--</executions>-->
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>${pmd.version}</version>
                <configuration>
                    <sourceEncoding>utf-8</sourceEncoding>
                    <minimumTokens>100</minimumTokens>
                    <targetJdk>${maven.compiler.target}</targetJdk>
                    <excludes>
                        <!--<exclude>**/*Bean.java</exclude>-->
                        <!--<exclude>**/generated/*.java</exclude>-->
                    </excludes>
                    <excludeRoots>
                        <!--<excludeRoot>target/generated-sources/stubs</excludeRoot>-->
                    </excludeRoots>
                </configuration>

                <!--在clean后自动执行check-->
                <!--<executions>-->
                    <!--<execution>-->
                        <!--<id>pmd-check</id>-->
                        <!--<phase>clean</phase>-->
                        <!--<goals>-->
                            <!--<goal>check</goal>-->
                        <!--</goals>-->
                    <!--</execution>-->
                <!--</executions>-->
            </plugin>
        </plugins>
    </build>                        

注:当项目通过Jenkins构建时,可以把注释掉的<executions>解注释,这样会在构建时的clean阶段后通过PMD静态分析源码是否符合规范,然后在compile阶段后通过FindBugs检查Bug。如果发现问题则会报错导致本次构建失败。

3、添加reporting插件

    <!--执行mvn clean compile site,会在target目录创建site目录生成项目网页报告-->
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>${pmd.version}</version>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <version>${findbugs.version}</version>
            </plugin>
        </plugins>

</reporting>

本文转自 zl1030 51CTO博客,原文链接:
http://blog.51cto.com/zl1030/2049874

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值