【トラブル】【Java】【Ant】 Checkstyle に関するトラブルシューティング

■ BUILD FAILED「 Unable to create a Checker: ... classpath {null}」が表示される

 * Antビルドで、Checkstyleを起動した時に以下のエラーが表示される

エラー内容

Buildfile: C:\eclipse\workspace\SampleJava\build.xml
run.checkstyle:

BUILD FAILED
C:\eclipse\workspace\SampleJava\build.xml:22: Unable to create a Checker: configLocation {C:\eclipse\workspace\SampleJava\libs\checkstyle\conf\checkstyle_checks.xml}, classpath {null}.

build.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="run.checkstyle" name="SampleJava">
  <property name="lib.dir" location="${basedir}/libs" />
  <property name="checkstyle.dir" location="${lib.dir}/checkstyle" />
  <property name="checkstyle.conf.dir" location="${lib.dir}/checkstyle/conf" />
  <property name="src.dir" location="${basedir}/src" />
  <property name="build.dir" location="${basedir}/class" />
  <property name="build.checkstyle.dir" location="${build.dir}/checkstyle" />
  <property name="build.reports.dir" location="${build.dir}/reports" />
  <path id="src.classpath">
    <pathelement location="${build.dir}" />
  </path>
  <taskdef
    resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties"
    classpath="${checkstyle.dir}/checkstyle-6.10.1-all.jar" />
  <target name="compile" description="Javaコンパイル">
    <delete dir="${build.dir}" />
    <mkdir dir="${build.dir}" />
    <javac srcdir="${src.dir}" destdir="${build.dir}" debug="true" debuglevel="vars,lines,source" includeantruntime="false" />
  </target>
  <target name="run.checkstyle" description="実行">
    <checkstyle config="${checkstyle.conf.dir}/checkstyle_checks.xml" failOnViolation="false">
      <fileset dir="${src.dir}" includes="**/*.java" />
    </checkstyle>
  </target>
</project>

原因

 * checkstyle_checks.xml内の
 「checkstyle.header.file」「checkstyle.suppressions.file」「checkstyle.importcontrol.file」が
 設定されていなかったため

解決策

 * checkstyle_checks.xml内の
 「checkstyle.header.file」「checkstyle.suppressions.file」「checkstyle.importcontrol.file」が
 設定する(以下の「修正後:build.xml(一部)」を参照)

修正後:build.xml(一部)

  <target name="run.checkstyle" description="実行">
    <checkstyle config="${checkstyle.conf.dir}/checkstyle_checks.xml" failOnViolation="false">
      <fileset dir="${src.dir}" includes="**/*.java" />
      <property key="checkstyle.header.file" value="${checkstyle.conf.dir}/java.header"/>
      <property key="checkstyle.suppressions.file" value="${checkstyle.conf.dir}/suppressions.xml"/>
      <property key="checkstyle.importcontrol.file" value="${checkstyle.conf.dir}/import-control.xml"/>
    </checkstyle>
  </target>
* 正式な設定は、以下の関連記事を参照のこと。
http://blogs.yahoo.co.jp/dk521123/35320406.html

Eclipse 上で、Checkstyle を使用した際のトラブル

 * 以下の関連記事を参照のこと。
http://blogs.yahoo.co.jp/dk521123/34630544.html

関連記事

Eclipse 上で、Checkstyle を使用した際のトラブル

http://blogs.yahoo.co.jp/dk521123/34630544.html