我在将checkstyle添加到构建文件时遇到问题。我一直在尝试按照http://checkstyle.sourceforge.net/anttask.html上的教程进行操作,并查看使用检查方式并找到问题解决方案的代码示例(例如No output from Checkstyle in ANT),但是当我构建文件时(终端)命令蚂蚁编译jar运行),没有什么沿线的checkstyle似乎发生。我想我已经将软件包插入了正确的目录中。这是我的构建文件代码的一部分:
<property name="checkstyle.dir" location="home/lakers/NoteTaker/analysis/bin/checkstyle-5.6" />
...
<target name="checkstyle">
<taskdef resource="checkstyletask.properties">
<classpath>
<pathelement location="home/lakers/NoteTaker/analysis/bin"/>
<pathelement location ="home/lakers/NoteTaker/analysis/bin/checkstyle-5.6/checkstyle-5.6-all.jar"/>
</classpath>
</taskdef>
<echo>Starting checkstyle</echo>
<checkstyle config="sun_checks.xml" failOnViolation="false">
<fileset dir="src" includes="**/*.java"/>
<fileset dir="NoteTaker/NoteTaker/src/notetaker" includes="**/*.java"/>
<formatter type="plain"/>
</checkstyle>
<echo>Checkstyle finished</echo>
</target>
如果我说的不清楚,请告诉我,我会尽力澄清。非常感谢您的帮助。 :)
答案 0 :(得分:3)
确保存在以下文件:
checkstyle-5.6-all.jar
- 在 - home/lakers/NoteTaker/analysis/bin/checkstyle-5.6/checkstyle-5.6-all.jar
,sun_checks.xml
- 在您的 base directory
也许你错过了sun_checks.xml的正确目录。
我制作了一个构建文件并且工作正常。
目录结构是:
project
|--------src
| |------packages/*.java files
|
|--------files
|------checkstyle-all-5.6.jar
|------sun_checks.xml
我已将 checkstyle-all-5.6.jar 和* sun_checks.xml *复制到此项目目录。
我的build.xml看起来像:
<?xml version="1.0"?>
<project name="XYZ" basedir="." default="job">
<taskdef resource="checkstyletask.properties" classpath="${basedir}/files/checkstyle-5.6-all.jar" />
<target name="job">
<checkstyle config="files/sun_checks.xml"
failureProperty="checkstyle.failure" failOnViolation="false">
<fileset dir="src" includes="**/*.java" />
<formatter type="plain" />
</checkstyle>
<echo>Job is Done</echo>
</target>
</project>
我已经运行了这个构建文件并正确地给出了违规行为。