问题
I have set up my checkstyle checks in my pom.xml as follows
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.10</version>
<configuration>
<suppressionsLocation>
checkstyle-suppressions.xml
</suppressionsLocation>
<suppressionsFileExpression>
checkstyle-suppressions.xml
</suppressionsFileExpression>
</configuration>
</plugin>
</plugins>
</reporting>
my checkstyle-supressions.xml file contains the following
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.0//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
<suppressions>
<suppress checks="JavadocStyleCheck"
files="**/*.java"
/>
<suppress checks="JavadocTypeCheck"
files="**/*.java"
/>
<suppress checks="JavadocVariableCheck"
files="**/*.java"
/>
<suppress checks="FileTabCharacterCheck"
files="**/*.java"
/>
</suppressions>
I want that when i run mvn site, the check style plugin does not report any JavaDoc comments or errors relating to tab characters. But this does not work. How can i achieve this ?
Kind Regards
回答1:
The CheckStyle:SuppressionFilter told us as
A suppressions XML document contains a set of
suppress
elements, where eachsuppress
element can have the following attributes:
- files - a regular expression matched against the file name associated with an audit event. It is mandatory.
- checks - a regular expression matched against the name of the check associated with an audit event. Optional if id is specified.
- id - a string matched against the id of the check associated with an audit event. Optional if checks is specified.
- lines - a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer. It is optional.
- columns - a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer. It is optional.
Since the files
is a regular expression
, you can test the configure online at Regular Expression Test Page for Java.
If the files
is **/*.java
, when apply the regular expression
with com.test.My.java
the result is failure as Dangling meta character '*' near index 0 **/*.java ^
Then the solution is setting the files
as .*\.java
, when apply the regular expression
with com.test.My.java
the result is matches(): yes, lookingAt(): yes, find(): yes and group(0): com.test.My.java.
The plugin configuration should be the following:-
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.10</version>
<configuration>
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
</configuration>
</plugin>
The checkstyle:checkstyle told us as
suppressionsLocation: Specifies the location of the suppressions XML file to use. This parameter is resolved as resource, URL, then file. If successfully resolved, the contents of the suppressions XML is copied into the
${project.build.directory}/checkstyle-supressions.xml
file before being passed to Checkstyle for loading.suppressionsFileExpression The key to be used in the properties for the suppressions file. Default value is: checkstyle.suppressions.file.
Please refer to Maven Checkstyle Plugin: Using a Suppressions Filter for further information.
I hope this may help.
来源:https://stackoverflow.com/questions/15573743/checkstyle-checks-not-been-ignored