1:下载checkstyle
下载checkstyle-8.5-bin.tar.gz (checkstyle主包配置文件)。下载地址:https://sourceforge.net/projects/checkstyle/files/checkstyle/8.5/checkstyle-8.5-src.tar.gz/download
下载checkstyle-8.5-src.tar.gz(build.xml文件)。下载地址:https://sourceforge.net/projects/checkstyle/files/checkstyle/8.5/checkstyle-8.5-src.tar.gz/download
2:写相应的ant脚本,如在build.xml中,可以加入下面的target,checkstyle在/opt/checkstyle/checkstyle-8.5下,java包在/root/.hudson/jobs/svn-test/workspace下:
vim build.xml
<project name="checkstyle" default="checkstyle.checkstyle" basedir=".">
<!--声明checkstyle相关的java包-->
<path id="project.sourcepath">
<fileset dir="src"
includes="**/*"
excludes="it/resources/**/*,test/resources/**/*,test/resources-noncompilable/**/*,main/resources-noncompilable/**/*"/>
</path>
<target name="checkstyle">
<taskdef resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties"
classpath="/opt/checkstyle/checkstyle-8.5/checkstyle-8.5-all.jar"/>
<!--声明参考checkstyle检查标准文件的路径、项目路径、相关jar和java代码-->
<checkstyle config="/opt/checkstyle/checkstyle-8.5/src/main/resources/sun_checks.xml" failureProperty="checkstyle.failure" failOnViolation="false">
<fileset dir="/root/.hudson/jobs/svn-test/workspace/" includes="**/*.jar"/>
<fileset dir="/root/.hudson/jobs/svn-test/workspace" includes="**/*.java"/>
<!--<formatter type="plain"/>--> <!--ant时输出告警信息-->
<!--生成checkstyle xml报表的文件和路径-->
<formatter type="xml" toFile="/root/.hudson/jobs/svn-test/workspace/checkstyle-result.xml"/>
</checkstyle>
<!-- <formatter type="xml" tofile="/root/.hudson/jobs/svn-test/workspace/checkstyle-result.xml"/>
<fileset dir="/root/.hudson/jobs/svn-test/workspace/" includes="**/*.jar"/>
<fileset dir="/root/.hudson/jobs/svn-test/workspace/" includes="**/*.java"/>
</checkstyle>
-->
</target>
</project>
3:配置hudson执行build.xml中的ant脚本
4:配置Hudson,下载Hudson的checkstyle plugin,进入到工程配置界面,找到Post-build Actions项,里面多出一个Publish Checkstyle analysis results选项。做相应的配置,根据不同的项目要求设置不同的配置,可参照Help.
5:运行工程。可得到如下结果:
图示1:
图示2:
图示3:
文章末尾固定信息
评论