LoginSignup
8
8

More than 5 years have passed since last update.

Gradle + Checkstyle で SuppressionFilter を使う方法

Last updated at Posted at 2013-06-24

SuppressionFilter を使うときはファイルパスを指定しないといけないので面倒です。

${project}/configuration/checkstyle.xml

<module name="Checker">
  <property name="charset" value="UTF-8"/>
  ...
  <module name="SuppressionFilter">
    <property name="file" value="${checkstyleConfigDir}/checkstyle-suppressions.xml"/>
  </module>
</module>

${checkstyleConfigDir} を Gradle からインジェクトします。Gradle 経由で Checkstyle を実行するときは charset 指定も忘れずに。

${project}/configuration/checkstyle-suppressions.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suppressions PUBLIC
    "-//Puppy Crawl//DTD Suppressions 1.1//EN"
    "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
    <suppress checks=".*" files="src/test/java/.*" />
</suppressions>

${project}/build.gradle

def checkstyleConfigDir = new File(buildscript.sourceFile.parentFile, configurationDir)
checkstyle {
    configFile = new File(checkstyleConfigDir, "checkstyle.xml")
    configProperties.checkstyleConfigDir = checkstyleConfigDir
}
8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8