Search code examples
javawindowsmavenintellij-ideacheckstyle

Maven: On Windows Checkstyle plug-in does not apply suppression filter


On Linux/MacOS, Checkstyle plug-in applies suppression filter as expected, but on Windows it seems as if the filter is not applied and the build fails with the exact warnings intended to be suppressed in the suppressions.xml file.

What could be the problem?

Snippet from the pom.xml:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <phase>process-sources</phase>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
            <configLocation>google_checks.xml</configLocation>
             <suppressionsLocation>foo/bar/checkstyle/suppressions.xml</suppressionsLocation>
             <consoleOutput>true</consoleOutput>
            <failsOnError>true</failsOnError>
            <failOnViolation>true</failOnViolation>
            <violationSeverity>warning</violationSeverity>
            <includeTestSourceDirectory>true</includeTestSourceDirectory>
        </configuration>
      </plugin>

And this is the whole suppressions.xml:

<!DOCTYPE suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN"
    "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
    <suppress checks="NonEmptyAtclauseDescription" files=".*"/>
    <suppress checks="AbbreviationAsWordInName" files="/foo/bar/.*IT.java"/>
    <suppress checks="JavadocMethod" files="/foo/bar/.*"/>
</suppressions>

Solution

  • Unix based systems(Linux/MacOS), use forward slash "/" as a path separator. But Windows uses backward slash "\" for that purpose. That's why regex did not match the path to the files and did not apply any suppressions. One way for the path Regex to make it work on both Linux/MacOS and Windows is to replace slashes with “[/\\]” and accept both shashes as a path separator. Example:

    <suppress checks="AbbreviationAsWordInName" files="[/\\]foo[/\\]bar[/\\].*IT.java"/>