Findbugs Maven插件 - findbugs-exclude包含多个项目

Ron*_*ero 10 maven-2 findbugs

我有一个多项目设置,使用Maven和Findbugs插件.我需要在其中一个子项目中排除一些文件,所以我将其添加到findbugs-exclude.xml.当我在子项目中构建时,这是有效的.

我的问题出现在我尝试建立顶级水平时.Maven没有findbugs-exclude.xml在子项目中找到它.所以它不会忽略我的错误,因为它们而失败.我可以将我findbugs-exclude.xml放在顶级目录中,并且排除有效.但这是污染最高级别的,并且不会受到好评.

有没有办法让Maven插件使用findbugs-exclude.xml子目录中的文件?最好在顶层几乎没有变化?

Jam*_*s K 4

一种解决方案是创建一个包含 findbugs-excludes.xml 的单独项目,然后使用依赖项插件将其解压并将其放置在本地需要的位置,如下所示:

<profile>
    <id>static-analysis</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-findbugs</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.myproject</groupId>
                                    <artifactId>my-findbugs</artifactId>
                                    <version>0.1-SNAPSHOT</version>
                                    <type>jar</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>src/main/findbugs/</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                            <!-- other configurations here -->
                            <excludes>META-INF/</excludes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <configuration>
                    <xmlOutput>true</xmlOutput>
                    <!-- Optional directory to put findbugs xdoc xml report -->
                    <xmlOutputDirectory>target/findbugs</xmlOutputDirectory>
                    <effort>Max</effort>
                    <threshold>Low</threshold>
                    <excludeFilterFile>src/main/findbugs/findbugs-excludes.xml</excludeFilterFile>
                </configuration>
                <executions>
                    <execution>
                        <id>findbugs-run</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>
Run Code Online (Sandbox Code Playgroud)

通过这种方法,如果需要,您可以跨项目共享此排除文件,这可能是好事也可能是坏事,具体取决于您如何看待它:) 另外,考虑一下,如果您有一个专门的 findbugs 项目,您可以创建不同的风格使用分类器进行排除,并根据上下文使用特定的分类器。它并不完美,但对我有用。

HTH,詹姆斯