Jenkins系列——使用checkstyle进行代码规范检查
1.目标
通过jenkins使用checkstyle对代码进行规范检查并生成html报告。
构建采用shell。
2.环境
checkstyle5.7(如果是Linux版本选用tar.gz格式)
①其他默认环境(如jdk)同前 。
②checkstyle没有选择最新版7.6.1是因为7.6.1版本没有将xml格式的报告转换为html报告的xsl文件。
③ant版本不宜选择太高,因为高版本可能需要JDK8+的支持。
④jenkins checkstyle插件主要是用于出版checkstyle报告,这里不涉及。
3.前置工作
3.1 安装ant及checkstyle。
3.2 编写ant脚本执行checkstyle构建。
<?xml version="1.0" encoding="UTF-8"?>
<project name="checkstyle" default="checkstyle" basedir="D:\data\jenkins\workspace\CheckstyleDemo_CODE"> <!-- 检查源码的路径 ,每个作业不同-->
<target name="init">
<tstamp/>
<!-- 设置作业工作目录,每个作业不同 -->
<property name="project.dir" value="D:\data\jenkins\workspace\CheckstyleDemo_CODE"/>
<!-- 输出报告的路径 -->
<property name="project.checkstyle.report.dir" value="${project.dir}\checkstyle_report"/>
<property name="project.checkstyle.result.name" value="checkstyle-result.xml"/>
<property name="project.checkstyle.report.name" value="checkstyle-report.html"/>
<!-- 检测规则存放路径 -->
<property name="checkstyle.config" value="D:\data\jenkins\myConf\checkstyle-5.7\sun_checks.xml"/>
<property name="checkstyle.report.style" value="D:\data\jenkins\myConf\checkstyle-5.7\contrib\checkstyle-author.xsl"/>
<property name="checkstyle.result" value="${project.checkstyle.report.dir}\${project.checkstyle.result.name}"/>
<property name="checkstyle.report" value="${project.checkstyle.report.dir}\${project.checkstyle.report.name}"/>
<mkdir dir="${project.checkstyle.report.dir}"/>
</target> <taskdef resource="checkstyletask.properties" classpath="D:\data\jenkins\myConf\checkstyle-5.7\checkstyle-5.7-all.jar" />
<target name="checkstyle" depends="init" description="check java code and report." >
<checkstyle config="${checkstyle.config}" failureProperty="checkstyle.failure" failOnViolation="false">
<formatter type="xml" tofile="${checkstyle.result}" />
<fileset dir="${project.dir}\src" includes="**/*.java" /> <!-- 检查源代码的存放路径 -->
</checkstyle>
<!-- 通过指定的xsl模版文件生成一份html的报告,这里生成的文件用于邮件发送时附加上,另外Jenkins插件也会生成可视化的结果 -->
<style in="${checkstyle.result}" out="${checkstyle.report}" style="${checkstyle.report.style}" />
</target>
</project>
checkstyle作业构建脚本
每个checkstyle作业都应该新建一个类似的ant脚本,只需要更改作业源码路径(2处)。
4.jenkins配置
新建一个自由风格的job,配置如下:

这里源码使用了码云的zheng项目,直接放到了该作业工作区的src目录之下。
5.构建结果
在工作区中新建了一个checkstyle_report目录,目录中生成了checkstyle_report.xml和checkstyle_report.html文件。

html格式的报告内容如下:

Jenkins系列——使用checkstyle进行代码规范检查的更多相关文章
- Jenkins系列——使用checkstyle进行代码规范检查【升级版】
1.背景 在<Jenkins系列——使用checkstyle进行代码规范检查>一文中完成了ant实现代码规范检查的例子.但存在以下缺陷: 每个作业都需要配置一个不同的checkstyle ...
- Java-idea-Checkstyle自动化代码规范检查
一.概述 CheckStyle是SourceForge下的一个项目,提供了一个帮助JAVA开发人员遵守某些编码规范的工具.它能够自动化代码规范检查过程,从而使得开发人员从这项重要,但是枯燥的任务中解脱 ...
- 扩展阿里p3c实现自定义代码规范检查
前段时间fastjson报出了漏洞,只要打开setAutoType特性就会存在风险,自己测试环境的一个项目被揪出来了-_-!.虽然改动很小,但就是觉得憋屈.fastjson还是挺好的,想着禁用的话太 ...
- linux 创建svn版本库,并在svn上配置checkstyle做代码风格检查
一.创建SVN版本库 1.安装svn服务器 yum install subversion 2.查看版本 svnserve --version 3.建立SVN版本库目录(即你的SVN服务器里面的文件存放 ...
- 玩转Eclipse — 自动代码规范检查工具Checkstyle
大项目都需要小组中的多人共同完成,但是每个人都有自己的编码习惯,甚至很多都是不正确的.那么如何使小组所有开发人员都遵循某些编码规范,以保证项目代码风格的一致性呢?如果硬性地要求每个开发人员在提交代码之 ...
- 在intellij中使用checkStyle进行代码规范
1 编写代码检测规则可以参考阿里和google的规则和checkstyle的官网文档.checkstyle官网地址http://checkstyle.sourceforge.net/ 假设自己的sty ...
- Jenkins系列——使用SonarQube进行代码质量检查
1.目标 之前已经写过一篇关于Jenkins和SonarQube的一篇博客<jenkins集成sonar>,本文在参考前文的基础上,做了详细的补充. 使用SonarQube进行代码质量检查 ...
- SwiftLint:代码规范检查工具介绍
Swift-CodeStyle Checker:SwiftLint 介绍: SwiftLint 是一个用于强制检查 Swift 代码风格和规定的一个工具,基本上以 GitHub's Swift 代码风 ...
- IDEA 阿里巴巴代码规范检查插件
1.问题概要 大家都想写出规范的代码,可规范的标准是什么勒,估计每个人心中的标准都不是完全一致的 在分工合作越来越精细化的时代,我们需要一个最大程度接近公认的规范,这里我们以阿里巴巴的代码规范作为参考 ...
随机推荐
- esp8266 终于装上固件了!半个月了!开始进军简单粗暴的lua语言!!
第一次测试2017-10-2720:33:33 感谢这位大神的汇总资料太详细了 http://www.cnblogs.com/yangfengwu/p/7524326.html --first tes ...
- nginx添加编译lua模块
一 .安装LuaJit 1.下载LuaJit # wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz 2.编译安装 # tar xzvf LuaJI ...
- linux_Nginx日志
错误信息日志配置: 日志文件默认:/application/nginx/logs/erroe.log error_log logs/error.log error; # 不写默认就有,默认error, ...
- 6_css选择器
如何应用css样式? 找标签 写样式 如何找出标签? class选择器 .类名(注意前面点){ 样式 } .a{ color: green; } <p class="a"&g ...
- junit4X系列--Builder、Request与JUnitCore
原文出处:http://www.blogjava.net/DLevin/archive/2012/05/12/377957.html.感谢作者的无私分享. 初次用文字的方式记录读源码的过程,不知道怎么 ...
- C# 值类型,引用类型区别
值类型/引用类型 作为所有类型的基类,System.Object提供了一组方法,这些方法在所有类型中都能找到,其中包含toString方法及clone等方法. 引用类型和值类型都继承自System.O ...
- 在nagios中使用nrpe自定义脚本
nrpe的安装 tar xvfz nrpe-2.13.tar.gz cd nrpe-2.13 ./configure make all make install-plugin make inst ...
- 【转】Awk 命令学习总结、AWk命令系列学习(linux shell)
前面的话 学习linux 的同人,都知道linux shell文本处理能力非常强大.有一组强大的文本处理工具:grep,sed,awk . 其中grep 经常用作查找匹配文本.sed用作文本编辑替换. ...
- 【JDK1.8】JDK1.8集合源码阅读——Set汇总
一.前言 这一篇里,我将对HashSet.LinkedHashSet.TreeSet进行汇总分析,并不打算一一进行详细介绍,因为JDK对Set的实现进行了取巧.我们都知道Set不允许出现相同的对象,而 ...
- C#使用Redis
一,引入dll 1.ServiceStack.Common.dll 2.ServiceStack.Interfaces.dll 3.ServiceStack.Redis.dll 4.ServiceSt ...