【问题标题】:Maven Findbugs plugin - How to run findbug on the test classesMaven Findbugs 插件 - 如何在测试类上运行 findbug
【发布时间】:2016-01-18 23:55:37
【问题描述】:

Maven 版本:3.3.3。 Findbugs 插件版本:3.0.1

  1. 我正在使用findbugs-maven-plugin,我需要运行 findbugs src 和测试类的插件。目前仅适用于源类

    Target
    |_ classes
    |_ test-classes
    |_ findbugs (only have results regarding classes folder)
    
  2. 我需要为 PMD 插件做同样的事情。可能是同样的提示?

相关问题:

Findbugs maven 配置:

<profile>
    <id>findbugs</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <version>${findbugs.version}</version>
                <configuration>
                    <effort>Max</effort>
                    <failOnError>true</failOnError>
                    <threshold>Low</threshold>
                    <xmlOutput>true</xmlOutput>
                    <includeTests>true</includeTests>
                    <excludeFilterFile>findbugs-exclude.xml</excludeFilterFile>
                </configuration>
                <executions>
                    <execution>
                        <id>analyze-compile</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                            <goal>findbugs</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

【问题讨论】:

    标签: java maven findbugs


    【解决方案1】:

    findbugs-maven-plugin的配置中,您需要将includeTests元素显式设置为true,以便FindBugs分析测试类:

    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>findbugs-maven-plugin</artifactId>
      <version>3.0.1</version>
      <configuration>
        <!-- rest of configuration -->
        <includeTests>true</includeTests>
      </configuration>
    </plugin>
    

    此外,插件应该绑定到verify 阶段,以便在编译源和测试类之后执行 FindBugs。

    对于maven-pmd-plugin,其实是一样的:必须在插件配置中将元素includeTests设置为true

    【讨论】:

    • 非常感谢,但我们现在有 135 个错误(在测试中),而不是 0 个错误(在 src 中)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-04
    • 1970-01-01
    • 2015-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-16
    相关资源
    最近更新 更多