SpotBugs Maven Plugin exclude a directory

这一生的挚爱 提交于 2019-12-04 10:11:21

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. First create an XML filter file specifying the criteria for the directory(s) to be excluded.

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

As a simple example:

  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>
    

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

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

Notes:

  • There is also an <includeFilterFile> tag. See the section titled Specifying which bug filters to run in the usage documentation.

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

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