首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Findbugs Maven插件-findbugs-排除多个项目

Findbugs Maven插件-findbugs-排除多个项目
EN

Stack Overflow用户
提问于 2010-10-28 02:03:30
回答 5查看 11.5K关注 0票数 13

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

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

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

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2010-12-09 18:57:40

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

代码语言:javascript
复制
<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>

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

哈哈,詹姆斯

票数 4
EN

Stack Overflow用户

发布于 2011-07-23 00:22:15

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

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

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

代码语言:javascript
复制
<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>

并在父级中配置findbugs时引用以下属性:

代码语言:javascript
复制
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>findbugs-maven-plugin</artifactId>
    <configuration>
      <excludeFilterFile>${myproject.parent.shared.resources}/findbugs-exclude.xml</excludeFilterFile>
    </configuration>
    ...
</plugin>

所有直接子项目现在都将运行findbugs,引用父项目中的配置文件。如果您有多个级别的项目嵌套,则必须重写子父级中的myproject.parent.basedir。例如,如果您有父<-子-父<-子,则应放入:

代码语言:javascript
复制
<properties>
    <myproject.parent.basedir>${project.parent.parent.basedir}</myproject.parent.basedir>
</properties>
票数 3
EN

Stack Overflow用户

发布于 2020-04-27 14:41:48

我之所以使用spotbugs,是因为findbugs已被弃用,不再支持。我在我的项目中也遇到了同样的问题。

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

代码语言:javascript
复制
parent-module:
  |
  -- sub-module-1
  |     |
  |     -- ...
  |     |
  |     --pom.xml
  |
  -- sub-module-2
  |     |
  |     -- ...
  |     |
  |     --pom.xml
  |
  -- ...
  |
  -- sub-module-n
  |     |
  |     -- ...
  |     |
  |     --pom.xml
  |
  -- ...
  |
  -- exclude-filter.xml
  |
  --pom.xml

parent-modulespotbugs配置

代码语言:javascript
复制
...
<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>
...

不,您可以从parent-project或任何sub-project执行mvn test-compile,它将由spotbugs检查源代码和测试源代码问题。

考虑一下示例:https://github.com/koresmosto/mif

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4036229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档