有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java CheckStyle检查未被忽略

我已经在pom中设置了我的checkstyle检查。xml如下所示

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

我的支票样式限制。xml文件包含以下内容

<?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>

我希望当我运行mvn站点时,check样式插件不会报告任何与标签字符相关的JavaDoc注释或错误。但这是行不通的。我怎样才能做到这一点

问候


共 (1) 个答案

  1. # 1 楼答案

    那位CheckStyle:SuppressionFilter告诉我们

    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.

    由于files是一个regular expression,您可以在Regular Expression Test Page for Java处在线测试configure

    如果files**/*.java,当regular expressioncom.test.My.java一起应用时,结果是Dangling meta character '*' near index 0 **/*.java ^失败

    然后,解决方案是files设置为.*\.java,当使用com.test.My.java应用regular expression时,结果是匹配():yeslookingAt():yes查找():yes组(0):com。测验我的java

    插件配置应如下所示:

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

    那位checkstyle:checkstyle告诉我们

    1. 抑制位置:指定要使用的抑制XML文件的位置。 此参数解析为资源、URL,然后是文件。如果成功解析,抑制XML的内容将被复制到${project.build.directory}/checkstyle-supressions.xml文件中,然后传递给Checkstyle进行加载

    2. suppressionsFileExpression要在抑制文件的属性中使用的键默认值为:checkstyle。压制。文件

    详情请参阅Maven Checkstyle Plugin: Using a Suppressions Filter

    我希望这能有所帮助