首页 > 解决方案 > 计算存储库中忽略抑制文件的检查样式错误数

问题描述

我有一个 Maven 应用程序。在 pom.xml 它有一个maven-checkstyle-plugin3.1.1 配置的suppressions.xml文件。

我需要计算代码中检查样式错误的数量,而忽略了 suppresss.xml文件。

有没有办法通过命令行来做到这一点?

现在我想出了以下几点:

mvn clean checkstyle:checkstyle 
    -Dcheckstyle.config.location=http://example.com/checkstyle.xml
    -Dcheckstyle.config.logViolationsToConsole=true
    -Dcheckstyle.includeResources=false
    -Dcheckstyle.includeTestResources=false

或者

mvn clean org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1:checkstyle
    -Dcheckstyle.config.location=http://example.com/checkstyle.xml
    -Dcheckstyle.config.logViolationsToConsole=true
    -Dcheckstyle.includeResources=false
    -Dcheckstyle.includeTestResources=false

但它仍然考虑到 suppresss.xml。

标签: javamavencheckstylemaven-checkstyle-plugin

解决方案


没有好的方法可以做到这一点,但是有一个解决方法

  1. 用属性替换 checkstyle 抑制文件位置(例如 checkstyle.suppressions)
  2. 创建具有 0 个抑制的抑制文件,例如
<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
    "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
    "https://checkstyle.org/dtds/suppressions_1_2.dtd">

<suppressions>
</suppressions>

  1. 将步骤 1 中的属性设置为此“空”文件的路径。Cli 选项覆盖 pom.xml 中的值

此外,您可以在 checkstyle 配置中替换抑制文件的路径,并以相同的方式用属性覆盖它。


推荐阅读