鏈接:http://blog.csdn.net/kongxx/article/details/7750015
最近在整理maven工程,打算加入一次對代碼檢查和測試覆蓋率檢查的功能,因此想到了maven集成一些常用檢查工具的插件,下面就來介紹幾個常用插件的用法。
首先是介紹Checkstyle插件的集成,要添加Checkstyle插件,需要修改工程的pom.xml文件,添加以下插件配置
- <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>
- * 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.
- <properties>
- <checkstyle.config.location>my_checks.xml</checkstyle.config.location>
- </properties>
4. checkstyle插件的可執行任務如下:
- 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查看。