Excluding Lombok classes from Sonar coverage report

Vincent F picture Vincent F · Nov 22, 2017 · Viewed 13.8k times · Source

Latest Jacoco plugin (still in snapshot version, 0.7.10-SNAPSHOT), has a nice new feature to filter out the Lombok generated code (https://github.com/jacoco/jacoco/wiki/FilteringOptions). All we need to do is add a lombok.config file at the root of the repository with:

lombok.addLombokGeneratedAnnotation=true 

When I generate the Jacoco report internally, I see the difference. However, when my regular quality job executes and publishes the result to Sonar, I get different (ie worse) results.

How come I don't have the same results in my local report and in Sonar? Is there any workaround?

Answer

Vincent F picture Vincent F · Nov 22, 2017

As mentionned here : https://github.com/jacoco/jacoco/pull/513#issuecomment-293176354

filtering is performed at a time of report generation (creation of html, xml, etc), not at a time of collection of execution information (creation of exec file). So that tools that read execution data directly instead of reading of xml (which is a kind of mistake on their side to rely on purely internal intermediate format, but what's done is done) and create their own report (such as SonarQube, Jenkins, etc) will need to update their dependency on JaCoCo once it will be released in order to get filtering for reports. We will notify explicitly downstream projects (in particular all mentioned above) about this when our release will be done. So once again - please be patient. Thank you for your understanding.

I didn't find a way for Sonar to read the end report instead of the exec file, so I guess we need to be patient and wait for the official 0.7.10 jacoco plugin release and then an update on Sonar side !

------ UPDATE May 9th 2018

New versions have been released, and I can confirm it works for me.

Using :

  • Sonar 6.7
  • SonarJava plugin 5.1.1.13214
  • jacoco maven plugin 0.8.1
  • lombok.addLombokGeneratedAnnotation=true in lombok.config

I now get much better coverage results reported to Sonar, as Lombok generated code is now ignored. It really helps identifying what the "real" uncovered areas are, and whether it's risky or not.