Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Findbugs plugin - How to run findbug on the test classes

Maven version: 3.3.3. Findbugs plugin version: 3.0.1

  1. I'm using the findbugs-maven-plugin and I need to run findbugs plugin on src and test classes. Currently, it is only applied to the source classes

    Target
    |_ classes
    |_ test-classes
    |_ findbugs (only have results regarding classes folder)
    
  2. I need to do the same for the PMD plugin. Same hint maybe?

Related issues:

  • FindBugs filter file for ignoring JUnit tests
  • How to run findbug on the test code

Findbugs maven configuration:

<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>
like image 805
Leonel Avatar asked Oct 20 '15 10:10

Leonel


People also ask

How do you run FindBugs?

The preferred method of running FindBugs is to directly execute $FINDBUGS_HOME /lib/findbugs. jar using the -jar command line switch of the JVM (java) executable. (Versions of FindBugs prior to 1.3. 5 required a wrapper script to invoke FindBugs.)

How do you read a Findbug report?

The report will be generated in the folder target/site in the project directory under the name findbugs. html. You can also run the mvn findbugs:gui command to launch the GUI interface to browse the generated reports for the current project.


1 Answers

In the configuration of the findbugs-maven-plugin, you need to explicitely set the includeTests element to true for FindBugs to analyze the test classes:

<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>

Also, the plugin should be bound to the verify phase so that FindBugs is executed after compilation of source and test classes.

For the maven-pmd-plugin, it is actually the same: the element includeTests must be set to true in the plugin configuration.

like image 74
Tunaki Avatar answered Nov 16 '22 02:11

Tunaki