I am using Maven 3 and Checkstyle 2.9.1 in my java project and I have a common checkstyle configuration that we're using in several other projects as well. To avoid copying and editing that configuration file into my own project I use a suppressions file to disable all checks in some packages (generated code).
Now I want to suppress specific rules in all files.
This is my suppressions file:
<?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 files="my[\\/]generated[\\/]code[\\/]package" checks="."/>
<suppress files=".*\\.java$" checks="IndentationCheck"/>
<suppress files=".*\\.java$" checks="LineLengthCheck"/>
<suppress files=".*\\.java$" checks="ExplicitInitializationCheck"/>
<suppress files=".*\\.java$" checks="MemberNameCheck"/>
</suppressions>
This is my POM:
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<configLocation>${checkstyle.ruleset}</configLocation>
<suppressionsLocation>${checkstyle.suppressions}</suppressionsLocation>
</configuration>
</plugin>
</plugins>
</build>
I'm then calling
mvn checkstyle:checkstyle
to generate the reports, but the suppressed warnings are still in there.
What am I doing wrong here?
Checkstyle allows the definition of a list of files and their line ranges that should be suppressed from reporting any violations (known as a suppressions filter ).
Then to disable Checkstyle, you use //CHECKSTYLE:OFF and //CHECKSTYLE:ON (default values) in your code. In this example, we want the disable it because we don't want to get the warning for the missing Javadoc tags for the getter/setter methods.
Overview. Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task. This makes it ideal for projects that want to enforce a coding standard.
Ok, I finally managed to build a working suppressions file for my checkstyle configuration.
My original problem was with the regex, so instead of files=".*\\.java$"
I'm now using files="."
to suppress special checks on all files. I also suppress all checks on certain files.
Here are some examples from my suppressions file:
<?xml version="1.0"?> suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN" "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
<!-- suppress certain checks on all files in a package -->
<suppress files="my[\\/]super[\\/]package[\\/]name" checks="ModifierOrderCheck|NeedBracesCheck|MagicNumberCheck"/>
<!-- suppress all checks on all files in a package -->
<suppress files="another[\\/]super[\\/]package[\\/]of[\\/]mine" checks=".*"/>
<!-- suppress certain checks on all files -->
<suppress files="." checks="IndentationCheck"/>
<suppress files="." checks="LineLengthCheck"/>
<suppress files="." checks="ExplicitInitializationCheck"/>
<suppress files="." checks="MemberNameCheck"/>
<suppress files="." checks="FinalClassCheck"/>
</suppressions>
If you need help with the Maven part of the configuration, see the answer of @Mawia.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With