Checkstyle can't find suppressions.xml

Viewed 4555

I'm using Gradle 5.0 and Checkstyle 8.15. I have a Java project with the following Checkstyle config and suppressions files:

  • config/checkstyle/checkstyle.xml
  • config/checkstyle/suppressions.xml

checkstyle.xml references suppressions.xml like so:

<module name="SuppressionFilter">
    <property name="file" value="config/checkstyle/suppressions.xml"/>
</module>

If I run checkstyle against my source, it fails:

$ ./gradlew checkstyleMain -xwebpack

  • Configure project : Defaulting to dev Spring profile

    Task :checkstyleMain FAILED

FAILURE: Build failed with an exception.

What went wrong: Execution failed for task ':checkstyleMain'. Unable to create Root Module: config {/Users/robert/dev/...}, classpath {/Users/robert/dev/...}.

Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/5.0/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1s 3 actionable tasks: 1 executed, 2 up-to-date

If I remove the reference to suppressions.xml, the build completes (checkstyle finds errors that would have been ignored if the suppressions were discovered).

My understanding from the doc is that the root for referenced files like config/checkstyle/suppressions.xml is the project root. That doesn't seem to be the case however.

Am I not setting up checkstyle properly?

1 Answers

If you are placing suppressions.xml inside project-dir/config/checkstyle/ , please use the following way,

<module name="SuppressionFilter">
    <property name="file" value="${config_loc}/suppressions.xml"/>
</module>

Latest version of checkstyle has config_loc variable set as project-dir/config/checkstyle/ automatically.

Related