Maven 2 Findbugs Maven插件-Findbugs排除多个项目

Maven 2 Findbugs Maven插件-Findbugs排除多个项目,maven-2,findbugs,Maven 2,Findbugs,我有一个多项目设置,使用Maven和Findbugs插件。我需要排除其中一个子项目中的一些文件,因此我将其添加到findbugs exclude.xml。当我在子项目中构建时,这是有效的 当我试图在顶层构建时,我的问题就来了。Maven在子项目中找不到findbugs exclude.xml。所以它不会忽略我的错误,也不会因此而失败。我可以将我的findbugs exclude.xml放在顶层目录中,排除就可以了。但这是在污染顶层,不会被看好 有没有办法让Maven插件使用子目录中的findbu

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

当我试图在顶层构建时,我的问题就来了。Maven在子项目中找不到
findbugs exclude.xml
。所以它不会忽略我的错误,也不会因此而失败。我可以将我的
findbugs exclude.xml
放在顶层目录中,排除就可以了。但这是在污染顶层,不会被看好


有没有办法让Maven插件使用子目录中的
findbugs exclude.xml
文件?最好在顶层进行很少或没有更改?

解决方案之一是创建一个单独的项目,其中包含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>

静力分析
org.apache.maven.plugins
maven依赖插件
打开findbugs的包装
过程资源
打开
com.myproject
我的findbugs
0.1-1快照
罐子
真的
src/main/findbugs/
META-INF/
org.codehaus.mojo
findbugs maven插件
真的
目标/findbugs
马克斯
低
src/main/findbugs/findbugs-excludes.xml
findbugs运行
编译
检查
使用这种方法,您可以在需要时跨项目共享此排除文件,这可能是好事,也可能是坏事,具体取决于您如何看待它:) 另外,考虑一下,如果您有一个专门的findbugs项目,您可以使用分类器创建不同风格的排除,并根据上下文使用特定的分类器。 这并不完美,但对我来说很管用

嗯,,
James

这是我在当前项目中所做的,它将
findbugs exclude.xml
放在父项目中(我知道您不需要),但它解决了在两个地方维护它的枯燥问题。它比解包简单,但要求完整的项目结构是本地的。(我认为解包解决方案将有助于在许多项目中使用相同的配置,就像在公司环境中一样。)

我将我的findbugs配置存储在
parent/src/main/resources/shared/findbugs exclude.xml
中,但只要它位于parent中,特定目录就无关紧要

然后,我使用属性来描述“共享”目录的位置:

<properties>
  <myproject.parent.basedir>${project.parent.basedir}</myproject.parent.basedir>
  <myproject.parent.shared.resources>${myproject.parent.basedir}/src/main/resources/shared</myproject.parent.shared.resources>
</properties>

对于公认的答案,更好的替代方法是使用maven远程资源插件。我喜欢James的方法,但是你需要调整clean插件来删除src文件夹中的未打包文件

根据James的建议,创建一个单独的项目,其中包含findbugs-excludes.xml,并将以下内容添加到其pom文件中:

  <build>
    <plugins>
        <plugin>
            <artifactId>maven-remote-resources-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <goals>
                        <goal>bundle</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <includes>
                    <include>**/*.*</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>

maven远程资源插件
1.5
捆
**/*.*
更新包含findbugs插件的pom文件:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-remote-resources-plugin</artifactId>
    <version>1.5</version>
    <executions>
        <execution>
            <id>process-remote-resources</id>
            <goals>
                <goal>process</goal>
            </goals>
            <configuration>
                <resourceBundles>
                    <resourceBundle>com.myproject:myartifactid:version</resourceBundle>
                </resourceBundles>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>findbugs-maven-plugin</artifactId>
    <configuration>
        ...
        ...
        <excludeFilterFile>${project.build.directory}/maven-shared-archive-resources/findbugs-exclude.xml</excludeFilterFile>
        ...        
    </configuration>
</plugin>

org.apache.maven.plugins
maven远程资源插件
1.5
处理远程资源
过程
myproject:myartifactid:version
org.codehaus.mojo
findbugs maven插件
...
...
${project.build.directory}/maven共享归档资源/findbugs-exclude.xml
...        
不要忘记更改com.myproject:myartifactid:version


maven remote resources插件将共享文件复制到目标文件夹,因此无需更改maven clean插件的默认行为

如果没有太多文件/包要排除,只需抑制一些警告-尝试使用@SuppressFBWarning注释。这应该适用于多个模块项目,并且可以在需要的特定项目和文件中添加注释

@SuppressFBWarning的依赖项

    <dependency>
        <groupId>com.google.code.findbugs</groupId>
        <artifactId>annotations</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.google.code.findbugs</groupId>
        <artifactId>jsr305</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>

com.google.code.findbugs
注释
3.0.1
假如
com.google.code.findbugs
jsr305
3.0.1
假如

我正在使用
spotbug
因为
findbugs
已被弃用,不再支持。我的项目中也有同样的问题

我的maven项目多模块结构与此类似:

parent-module:
  |
  -- sub-module-1
  |     |
  |     -- ...
  |     |
  |     --pom.xml
  |
  -- sub-module-2
  |     |
  |     -- ...
  |     |
  |     --pom.xml
  |
  -- ...
  |
  -- sub-module-n
  |     |
  |     -- ...
  |     |
  |     --pom.xml
  |
  -- ...
  |
  -- exclude-filter.xml
  |
  --pom.xml

父模块的
spotbug
配置:

...
<build>
    ...    
    <plugins>
        ...
        <plugin>
            <groupId>com.github.spotbugs</groupId>
            <artifactId>spotbugs-maven-plugin</artifactId>
            <version>4.0.0</version>
            <dependencies>
                <dependency>
                    <groupId>com.github.spotbugs</groupId>
                    <artifactId>spotbugs</artifactId>
                    <version>4.0.2</version>
                </dependency>
            </dependencies>
            <configuration>
                <effort>Max</effort>
                <threshold>Low</threshold>
                <includeTests>true</includeTests>
                <xmlOutput>true</xmlOutput>
                <excludeFilterFile>exclude-filter.xml</excludeFilterFile>
            </configuration>
            <executions>
                <execution>
                    <id>analyze-compile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        ...
    </plugins>
...
</build>
...

。。。
...    
...
com.github.spotbug

这方面有什么进展吗
parent-module:
  |
  -- sub-module-1
  |     |
  |     -- ...
  |     |
  |     --pom.xml
  |
  -- sub-module-2
  |     |
  |     -- ...
  |     |
  |     --pom.xml
  |
  -- ...
  |
  -- sub-module-n
  |     |
  |     -- ...
  |     |
  |     --pom.xml
  |
  -- ...
  |
  -- exclude-filter.xml
  |
  --pom.xml

...
<build>
    ...    
    <plugins>
        ...
        <plugin>
            <groupId>com.github.spotbugs</groupId>
            <artifactId>spotbugs-maven-plugin</artifactId>
            <version>4.0.0</version>
            <dependencies>
                <dependency>
                    <groupId>com.github.spotbugs</groupId>
                    <artifactId>spotbugs</artifactId>
                    <version>4.0.2</version>
                </dependency>
            </dependencies>
            <configuration>
                <effort>Max</effort>
                <threshold>Low</threshold>
                <includeTests>true</includeTests>
                <xmlOutput>true</xmlOutput>
                <excludeFilterFile>exclude-filter.xml</excludeFilterFile>
            </configuration>
            <executions>
                <execution>
                    <id>analyze-compile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        ...
    </plugins>
...
</build>
...