Eclipse – maven-checkstyle-plugin: Unable to parse suppressions.xml – invalid formats or checks format

checkstyleeclipsemaven

I am trying to add a suppressions.xml to my eclipse java project. My checkstyle-config.xml is in src/main/resources and suppressions.xml is in the same directory. I added this to the config file:

<module name="SuppressionFilter">
    <property name="file" value="src/main/resources/suppressions.xml"/>
</module>

And in pom.xml, I have

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.10</version>
    <configuration>
        <includeTestSourceDirectory>true</includeTestSourceDirectory>
        <failsOnError>true</failsOnError>
        <propertiesLocation>src/main/resources/checkstyle.build.properties</propertiesLocation>
        <configLocation>src/main/resources/checkstyle-config.xml</configLocation>                    
        <suppressionsLocation>src/main/resources/suppressions.xml</suppressionsLocation>
    </configuration>
</plugin>

When I run mvn verify from command-line OR through eclipse m2e plugin, I get this error:

Failed during checkstyle configuration: cannot initialize module SuppressionFilter – Cannot set property 'file' in module SuppressionFilter to 'src/main/resources/suppressions.xml': unable to parse src/main/resources/suppressions.xml – invalid files or checks format: InvocationTargetException -> [Help 1]

I even tried to change the path in checkstyle-config.xml to ${config_log} or ${basedir} but no luck so far.

Any help on this would be appreciable.

Update: I feel that the issue might not be with the file location but with the suppressions.xml file itself. Here is my suppressions.xml,

<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
     "-//Puppy Crawl//DTD Suppressions 1.1//EN"
     "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">

<suppressions>
    <suppress checks="JavadocPackage" files="src/test/java/**"/>
</suppressions>

Best Answer

The files attribute is a regular expression which is evaluated against the absolute file paths of the files checked. So the ** expression is invalid. Use something like this instead:

<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
    "-//Puppy Crawl//DTD Suppressions 1.1//EN"
    "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">

<suppressions>
    <suppress checks="JavadocPackage" files="[/\\]src[/\\]test[/\\]java[/\\].*"/>
</suppressions>

Using [/\\] instead of just / also supports both UNIX and Windows path separators.

Related Topic