maven配置pom文件添加PMD检查,添加checkStyle检查,JDepend等检查功能 加入PMD检查, 以下代码如果在reporting节点中加入则在mvn site中执行,如果在build节点中加入,则在build的时候自动运行检查。详细配置参考pmd插件使用说明
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
加入 checkstyle 检查,详细配置参考checkstyle插件使用说明,同样注意放置在reporting和build节点中的区别(所有报表类插件都要同样注意):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.5</version>
</plugin>
加入 simian 的支持,simian是一个支持代码相似度检查的工具,目前有maven插件,也有checkstyle的插件。它不仅可以检查java,甚至可以支持文本文件的检查。详细帮助信息参考这里。simian 的 maven插件在这里
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>simian-maven-plugin</artifactId>
<version>1.6.1</version>
</plugin>
</plugins>
...
</build>
加入 jdepend 检查,详细配置参考jdepend使用说明
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jdepend-maven-plugin</artifactId>
<version>2.0-beta-2</version>
</plugin>
加入 findbugz 检查,详细配置参考findbugz使用说明,
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.0.1</version>
</plugin>
加入javadoc生成,详细配置参考javadoc usage
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<configuration>
...
</configuration>
</plugin>
加入 jxr 支持,JXR是一个生成java代码交叉引用和源代码的html格式的工具,详细配置信息参考jxr usage。注意,jxr没有必要在build阶段运行。
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</reporting>
加入 Cobertura 支持,它是一个代码覆盖率工具,可以用来评估具有相应测试的源代码的比率。详细帮助在这里。另外一个功能相似的软件是EMMA,详细的帮助在这里。两个产品的比较文章在这里,个人倾向于都要用,因为给出的指标不一样,都有参考作用。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
<configuration>
<check>
<branchRate>85</branchRate>
<lineRate>85</lineRate>
<haltOnFailure>true</haltOnFailure>
<totalBranchRate>85</totalBranchRate>
<totalLineRate>85</totalLineRate>
<packageLineRate>85</packageLineRate>
<packageBranchRate>85</packageBranchRate>
<regexes>
<regex>
<pattern>com.example.reallyimportant.*</pattern>
<branchRate>90</branchRate>
<lineRate>80</lineRate>
</regex>
<regex>
<pattern>com.example.boringcode.*</pattern>
<branchRate>40</branchRate>
<lineRate>30</lineRate>
</regex>
</regexes>
</check>
</configuration>
<executions>
<execution>
<goals>
<goal>clean</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<reporting>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>emma-maven-plugin</artifactId>
<version>1.0-alpha-3-SNAPSHOT</version>
</plugin>
...
</plugins>
...
</reporting>
添加 javaNCSS 插件,它是一个java代码的度量工具,详细参考在这里。
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>javancss-maven-plugin</artifactId>
<version>2.0-beta-2</version>
</plugin>
</plugins>
</reporting>
]]>