继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Maven项目添加FindBugs、PMD插件

Qyou
关注TA
已关注
手记 255
粉丝 52
获赞 361

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>

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP