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?

Community
  • 1
  • 1
Enigo
  • 3,685
  • 5
  • 29
  • 54
  • 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 https://gleclaire.github.io/findbugs-maven-plugin/check-mojo.html – khmarbaise Jul 28 '16 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 '16 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. – SpaceTrucker Jul 28 '16 at 12:09
  • @SpaceTrucker thank you for suggestion. I'll give it a try. Anyway submitted [request](https://github.com/gleclaire/findbugs-maven-plugin/issues/44) for that feature. – Enigo Jul 29 '16 at 06: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 '16 at 07:58
  • @Enigo Thanks for the feedback. But I think you can already post a better answer than me since you can easily include the pom snippets required for the solution to work. I would have to create them. You should probably refer to my comment in your answer for attribution rules to be followed. – SpaceTrucker Jul 29 '16 at 08:03

1 Answers1

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

Community
  • 1
  • 1
Enigo
  • 3,685
  • 5
  • 29
  • 54