Maven Findbugs插件 - 如何在测试类上运行findbug

时间:2015-10-20 10:51:25

标签: java maven findbugs pmd

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插件做同样的事情。同样的暗示可能吗?

  3. 相关问题:

    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>
    

1 个答案:

答案 0 :(得分:7)

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