Search code examples
javamavenmaven-3maven-pluginfindbugs

How to make maven build failure when bug is found using findBug plugin


I have just added maven find bug plugin in my project pom:

<plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <version>3.0.4</version>
            <configuration>
                <xmlOutput>true</xmlOutput>
                <!-- Optional directory to put findbugs xdoc xml report -->
                <xmlOutputDirectory>target/site</xmlOutputDirectory>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>findbugs</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

for reporting I have added below:

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>findbugs-maven-plugin</artifactId>
        <version>3.0.4</version>
    </plugin>

Now when i run maven using install it gives me warnings below:

> [INFO] --- findbugs-maven-plugin:3.0.4:findbugs (default) @
> MovesouqBackend --- [INFO] Fork Value is true
>      [java] Warnings generated: 12 [INFO] Done FindBugs Analysis....

It shows there are 12 bugs as warning and build successful.

    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] --------------------------------------------------------------

----------

I want to make build fail when there is any warning found against findbug plugin and I want to show this warning as error. I have gone through plugin documentation but there is nothing about it. Please help.


Solution

  • Edit your configuration as:

    <executions>
       <execution>
       <phase>package</phase>
          <goals>
             <goal>findbugs</goal>
          </goals>
          <configuration>
             <failOnError>true</failOnError>
             <threshold>High</threshold>
          </configuration>
        </execution>
    </executions>
    

    Hope it helps you!