maven配置pom文件添加PMD检查,添加checkStyle检查,JDepend等检查功能

一、PMD是扫描 Java 源码并查找以下潜在问题: 
     从未用过的局部变量 
     空捕捉块(catch block) 
      从未用过的参数 
     空if声明 
     重复的导入声明 
    从未用过的私有方法 
     孤立的类 
     短型或长型变量及方法名 

加入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插件在这里

<plugins>	           
	    <plugin>	               
		<groupId>org.codehaus.mojo</groupId>               
		<artifactId>simian-maven-plugin</artifactId>               
		<version>1.6.1</version>	           
	    </plugin>        
	</plugins>

加入 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>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值