CheckStyle checks not been ignored

前提是你 提交于 2020-01-11 08:34:13

问题


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 each suppress element can have the following attributes:

  1. files - a regular expression matched against the file name associated with an audit event. It is mandatory.
  2. checks - a regular expression matched against the name of the check associated with an audit event. Optional if id is specified.
  3. id - a string matched against the id of the check associated with an audit event. Optional if checks is specified.
  4. 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.
  5. 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

  1. 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.

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!