3

I have integrated FindBugs plugin to fail the build in case of bugs.
Then using that brilliant answer I configured FindBugs to generate html reports (xml version is barely readable).
The problem is that I have failOnError property set to true, which means that the build would fail in case of bug.

 .....
 <configuration>
        .....
        <failOnError>true</failOnError>
 </configuration>

And then no html report would be generated.

I read about Maven build lifecycle and there is no such thing as "Execute on fail" (like finally block in Java). So, are there any possible workarounds? And shouldn't it be out-of the box Maven feature?

6
  • The HTML report is generated by the plugin which means if the plugin find a bug it fails. So if you like having the plugin generating a html report independent of failing you should file in an issue for the plugin gleclaire.github.io/findbugs-maven-plugin/check-mojo.html
    – khmarbaise
    Jul 28, 2016 at 10:22
  • @khmarbaise I guess in this case it's easier to request html report generation instead of xml one. Anyway it sounds like time-consuming solution.
    – Enigo
    Jul 28, 2016 at 10:44
  • How about using multiple runs of the findbugs plugin? In an early build phase run the plugin to generate the report. In a later run the plugin with failOnError set to true. This will slow down the build for the moment, but you would have an option to wait for a better solution. Jul 28, 2016 at 12:09
  • @SpaceTrucker thank you for suggestion. I'll give it a try. Anyway submitted request for that feature.
    – Enigo
    Jul 29, 2016 at 6:49
  • @SpaceTrucker yeah, your solution works, thank you again! And total build time growth is not that critical. So, why not to post it as an answer?)
    – Enigo
    Jul 29, 2016 at 7:58

1 Answer 1

6

Special thanks to @SpaceTrucker for workaround suggestion. Here is the configuration I ended up with:

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>findbugs-maven-plugin</artifactId>
   <version>3.0.4</version>
   <configuration>
       <effort>Max</effort>
       <threshold>Low</threshold>
       <findbugsXmlOutputDirectory>${project.build.directory}/findbugs</findbugsXmlOutputDirectory>
   </configuration>
   <executions>
       <execution>
           <id>noFailOnError</id>
           <phase>verify</phase>
           <goals>
               <goal>check</goal>
           </goals>
           <configuration>
               <failOnError>false</failOnError>
           </configuration>
       </execution>
       <execution>
           <id>failOnError</id>
           <phase>install</phase>
           <goals>
               <goal>check</goal>
           </goals>
           <configuration>
               <failOnError>true</failOnError>
           </configuration>
       </execution>
   </executions>
</plugin> 

The solution is to use different configurations in verify and install phases. Note, that according to that answer transformation (to html) is executed in verifyphase.

Issue was submitted for html report generation.

Results are also can be seen by simply run mvn findbugs:gui

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.