Maven Checkstyle Plugin集成

本文链接:http://blog.csdn.net/kongxx/article/details/7750015

最近在整理maven工程,打算加入一次对代码检查和测试覆盖率检查的功能,因此想到了maven集成一些常用检查工具的插件,下面就来介绍几个常用插件的用法。

首先是介绍Checkstyle插件的集成,要添加Checkstyle插件,需要修改工程的pom.xml文件,添加以下插件配置

[html]  view plain  copy
 print ?
  1. <project>  
  2.     ...  
  3.     <properties>  
  4.         <checkstyle.config.location>config/maven_checks.xml</checkstyle.config.location>  
  5.     </properties>  
  6.     ...  
  7.     <reporting>  
  8.         <plugins>  
  9.             <plugin>  
  10.                 <groupId>org.apache.maven.plugins</groupId>  
  11.                 <artifactId>maven-checkstyle-plugin</artifactId>  
  12.                 <version>2.9.1</version>  
  13.             </plugin>  
  14.   
  15.             <plugin>  
  16.                 <groupId>org.apache.maven.plugins</groupId>  
  17.                 <artifactId>maven-jxr-plugin</artifactId>  
  18.                 <version>2.3</version>  
  19.             </plugin>  
  20.         </plugins>  
  21.     </reporting>  
  22.     ...  
  23. </project>  
1. 其中可以修改使用的检查规则文件路径,插件默认提供了四个规则文件可以直接使用,不要手动下载,它们分别是:

[plain]  view plain  copy
 print ?
  1. * config/sun_checks.xml - Sun Microsystems Definition (default).  
  2. * config/maven_checks.xml - Maven Development Definitions.  
  3. * config/turbine_checks.xml - Turbine Development Definitions.  
  4. * config/avalon_checks.xml - Avalon Development Definitions.  
2. 也可以使用自定义的规则文件,比如自定义一个文件名为my_checks.xml,并放在工程根目录下,然后修改配置为如下:

[html]  view plain  copy
 print ?
  1. <properties>  
  2.     <checkstyle.config.location>my_checks.xml</checkstyle.config.location>  
  3. </properties>  
3. 另外,这里也添加了jxr插件,用来在生成的结果中可以通过link找到代码对应的行。

4. checkstyle插件的可执行任务如下:

[plain]  view plain  copy
 print ?
  1. mvn checkstyle:help           查看checkstyle-plugin的帮助:   
  2. mvn checkstyle:check          检查工程是否满足checkstyle的检查,如果没有满足,检查会失败,可以通过target/site/checkstyle.html查看。  
  3. mvn checkstyle:checkstyle     检查工程是否满足checkstyle的检查,如果没有满足,检查不会失败,可以通过target/site/checkstyle.html查看。  
  4. mvn checkstyle:checkstyle-aggregate     检查工程是否满足checkstyle的检查,如果没有满足,检查不会失败,可以通过target/site/checkstyle.html查看。  
5. 在运行完“mvn checkstyle:checkstyle”命令后,可以运行"mvn jxr:jxr"来使checkstyle的结果可以直接跳转到代码行位置。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值