Asad Khan
Asad Khan

Reputation: 513

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.

Upvotes: 5

Views: 4444

Answers (2)

Mahendra B
Mahendra B

Reputation: 362

You can simply use check goal with tag and set it false not to fail the build.

<plugin>
    <artifactId>findbugs-maven-plugin</artifactId>
    <configuration>
        <effort>Max</effort>
        <failOnError>false</failOnError>
    </configuration>
    <executions>
        <execution>
        <goals>
            <goal>check</goal>
        </goals>
        </execution>
    </executions>
    <groupId>org.codehaus.mojo</groupId>
    <version>3.0.5</version>
</plugin>

Upvotes: 0

Loic P.
Loic P.

Reputation: 711

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!

Upvotes: 5

Related Questions