Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 583
Asad Khan Avatar asked Feb 24 '17 14:02

Asad Khan


People also ask

What is FindBugs Maven plugin?

FindBugs is a static code analysis tool which identifies problems found from Java code. We can integrate FindBugs into our build process by using the FindBugs Maven plugin. This blog post identifies four typical use cases and describes how we can configure the FindBugs Maven plugin to support each use case.

How do I run FindBugs in Maven?

Generate FindBugs Report As Part of the Project Reports To generate the FindBugs report as part of the Project Reports, add the FindBugs plugin in the <reporting> section of your pom. xml. Then, execute the site plugin to generate the report.

How do you generate FindBugs 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.

Which of the following collaborates with FindBugs to visualize the code and identify the bugs in code?

PMD looks at the source code to find possible bugs, unused code, suboptimal code, complicated expressions, and duplicated code. FindBugs looks at the generated byte code to find possible errors.


1 Answers

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!

like image 138
Loic P. Avatar answered Nov 14 '22 22:11

Loic P.