且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SpotBugs Maven插件排除目录

更新时间:2021-12-10 02:26:00

可以使用SpotBugs从检查中排除目录,尽管这种方法与您为PMD描述的方法不同.这是一个两步过程:

It is possible to exclude a directory from inspection with SpotBugs, though the approach is different to the one you described for PMD. It is a two step process:

  1. 首先创建XML过滤器文件,指定用于目录要排除.

  1. First create an XML filter file specifying the criteria for the directory(s) to be excluded.

然后,在 pom.xml 中使用可选的<excludeFilterFile>设置引用该文件.不幸的是,该设置的文档非常简短.

Then, in pom.xml refer to that that file using the optional <excludeFilterFile> setting. Unfortunately, the documentation for that setting is very brief.

作为一个简单的例子:

  1. 创建一个名为 ignore.xml 的过滤器文件,其中包含以下文件,该文件引用名为 mydir 的目录:

  1. Create a filter file named ignore.xml containing the following which refers to a directory named mydir:

<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
    <Match>
        <Source name="~mydir\..*"/>
    </Match>
</FindBugsFilter>

标记<Source>的文档位于此处.请参阅 Java元素名称匹配一节.有关如何指定<Source>名称的详细信息.

The documentation for the <Source> tag is here. See the section on Java element name matching for details on how to specify the name of the <Source>.

然后在 spotbugs-maven-plugin 规范中的 pom.xml 中包含一个<excludeFilterFile>标记,以便 mydir 被SpotBugs忽略:

Then in pom.xml, in the specification for spotbugs-maven-plugin, include an <excludeFilterFile> tag so that mydir is ignored by SpotBugs:

<configuration>
  <excludeFilterFile>ignore.xml</excludeFilterFile>
</configuration>

注意:

  • 还有一个<includeFilterFile>标记.请参阅使用文档.

Source一样,SpotBugs还提供了几种其他方式来指定要包括哪些代码或从检查中排除哪些代码.有关PackageClassMethodLocalFieldType标记的信息,请参见过滤器文件.

As well as Source, SpotBugs provides several other ways to specify what code is to be included or excluded from checking. See the filter file documentation for the Package, Class, Method, Local, Field and Type tags.