Maven Checkstyle Plugin集成
2016-03-30 17:19
405 查看
本文链接:http://blog.csdn.net/kongxx/article/details/7750015
最近在整理maven工程,打算加入一次对代码检查和测试覆盖率检查的功能,因此想到了maven集成一些常用检查工具的插件,下面就来介绍几个常用插件的用法。
首先是介绍Checkstyle插件的集成,要添加Checkstyle插件,需要修改工程的pom.xml文件,添加以下插件配置
[html] view
plain copy
print?
<project>
...
<properties>
<checkstyle.config.location>config/maven_checks.xml</checkstyle.config.location>
</properties>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
</reporting>
...
</project>
1. 其中可以修改使用的检查规则文件路径,插件默认提供了四个规则文件可以直接使用,不要手动下载,它们分别是:
[plain] view
plain copy
print?
* config/sun_checks.xml - Sun Microsystems Definition (default).
* config/maven_checks.xml - Maven Development Definitions.
* config/turbine_checks.xml - Turbine Development Definitions.
* config/avalon_checks.xml - Avalon Development Definitions.
2. 也可以使用自定义的规则文件,比如自定义一个文件名为my_checks.xml,并放在工程根目录下,然后修改配置为如下:
[html] view
plain copy
print?
<properties>
<checkstyle.config.location>my_checks.xml</checkstyle.config.location>
</properties>
3. 另外,这里也添加了jxr插件,用来在生成的结果中可以通过link找到代码对应的行。
4. checkstyle插件的可执行任务如下:
[plain] view
plain copy
print?
mvn checkstyle:help 查看checkstyle-plugin的帮助:
mvn checkstyle:check 检查工程是否满足checkstyle的检查,如果没有满足,检查会失败,可以通过target/site/checkstyle.html查看。
mvn checkstyle:checkstyle 检查工程是否满足checkstyle的检查,如果没有满足,检查不会失败,可以通过target/site/checkstyle.html查看。
mvn checkstyle:checkstyle-aggregate 检查工程是否满足checkstyle的检查,如果没有满足,检查不会失败,可以通过target/site/checkstyle.html查看。
5. 在运行完“mvn checkstyle:checkstyle”命令后,可以运行"mvn jxr:jxr"来使checkstyle的结果可以直接跳转到代码行位置。
最近在整理maven工程,打算加入一次对代码检查和测试覆盖率检查的功能,因此想到了maven集成一些常用检查工具的插件,下面就来介绍几个常用插件的用法。
首先是介绍Checkstyle插件的集成,要添加Checkstyle插件,需要修改工程的pom.xml文件,添加以下插件配置
[html] view
plain copy
print?
<project>
...
<properties>
<checkstyle.config.location>config/maven_checks.xml</checkstyle.config.location>
</properties>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
</reporting>
...
</project>
1. 其中可以修改使用的检查规则文件路径,插件默认提供了四个规则文件可以直接使用,不要手动下载,它们分别是:
[plain] view
plain copy
print?
* config/sun_checks.xml - Sun Microsystems Definition (default).
* config/maven_checks.xml - Maven Development Definitions.
* config/turbine_checks.xml - Turbine Development Definitions.
* config/avalon_checks.xml - Avalon Development Definitions.
2. 也可以使用自定义的规则文件,比如自定义一个文件名为my_checks.xml,并放在工程根目录下,然后修改配置为如下:
[html] view
plain copy
print?
<properties>
<checkstyle.config.location>my_checks.xml</checkstyle.config.location>
</properties>
3. 另外,这里也添加了jxr插件,用来在生成的结果中可以通过link找到代码对应的行。
4. checkstyle插件的可执行任务如下:
[plain] view
plain copy
print?
mvn checkstyle:help 查看checkstyle-plugin的帮助:
mvn checkstyle:check 检查工程是否满足checkstyle的检查,如果没有满足,检查会失败,可以通过target/site/checkstyle.html查看。
mvn checkstyle:checkstyle 检查工程是否满足checkstyle的检查,如果没有满足,检查不会失败,可以通过target/site/checkstyle.html查看。
mvn checkstyle:checkstyle-aggregate 检查工程是否满足checkstyle的检查,如果没有满足,检查不会失败,可以通过target/site/checkstyle.html查看。
5. 在运行完“mvn checkstyle:checkstyle”命令后,可以运行"mvn jxr:jxr"来使checkstyle的结果可以直接跳转到代码行位置。
相关文章推荐
- 初学者关于ztree的浅谈
- CAGradientLayer基本使用方法
- c++Primer5,类设计者的工具
- [置顶] ubuntu下Qt for Android的安装及环境配置
- Android官方开发文档Training系列课程中文版:与其它APP交互之允许其它APP启动你的Activity
- phpexcel导入excel文件报the filename xxx is not recognised as an OLE file错误。
- Error:Cause: peer not authenticated
- 输出gradle执行task名称、输入输出文件和耗时
- 机器人--机器视觉的魅力
- 【暑假】[网络流]网络流知识总结
- 【暑假】[基本数据结构]根据BFS与DFS确定树
- 【暑假】[基本数据结构]根据in_order与post_order构树
- 【暑假】[基本数据结构]基本的数据结构知识点总结梳理
- 【暑假】[实用数据结构]动态连续和查询问题
- 【暑假】[实用数据结构]范围最小值问题(RMQ)
- 【暑假】[实用数据结构]动态范围查询问题
- 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!
- 【暑假】[实用数据结构]UVa11991 Easy Problem from Rujia Liu?
- 【暑假】[实用数据结构]UVAlive 3135 Argus
- 【暑假】[实用数据结构]UVa11997 K Smallest Sums