1

我在将 checkstyle 添加到我的构建文件时遇到问题。我一直在尝试遵循http://checkstyle.sourceforge.net/anttask.html上的教程,并查看使用 checkstyles 的代码示例并找到我的问题的解决方案(例如No output from Checkstyle in ANT),但是当我构建文件时(终端命令 ant compile jar run),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>

如果我说的有什么不清楚的地方,请告诉我,我会尽力澄清。非常感谢您的帮助。:)

4

1 回答 1

3

确保存在以下文件:

  1. checkstyle-5.6-all.jar -- 在 -- home/lakers/NoteTaker/analysis/bin/checkstyle-5.6/checkstyle-5.6-all.jar ,
  2. 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>

我已经运行了这个构建文件并正确地给出了违规行为。

于 2013-08-14T13:26:10.420 回答