项目组开发项目需要使用eclipse的checkstyle插件来对代码进行静态检查,避免一些不符合编码规范的代码出现。
后来项目范围逐渐增大,就有搭建持续集成服务器的必要了,并且类似于checkstyle这样的静态分析工具也需要同时进行配置。
最开始是别人搭建的,参照了网上的示例,使用的是ant+checkstyle,但是在使用的时候却发现了问题。有些工程是可以正确的分析并生成报告的,而有些工程却会出现异常:Got an exception - java.lang.RuntimeException: Unable to get class information for xx.xxx.xxx.XXException。不是JDK的Exception,一般都是系统中自定义的Exception。
经过调查,确定解决方法。
就是为checkstyle task追加classpath属性,其中配置了自定义的Exception所在的jar文件或class文件。
如下:
<target name="checkstyle" depends="">
<checkstyle config="${checkstyle.config}">
<classpath>
<path refid="lib.path" />
</classpath>
<fileset dir="${src.dir}" includes="**/*.java" />
<formatter type="plain" />
<formatter type="xml" toFile="${report.dir}/${ant.project.name}.xml" />
</checkstyle>
</target>