Excluding Lombok classes from Sonar coverage report

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.


First you have to check your lombok version is at least 1.16.14

pom.xml:

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <scope>provided</scope>
    <version>1.16.14</version>
</dependency>

Then you have to check that your Jacoco version is at least 0.8.0

pom.xml:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.0</version>
    <!-- // -->
</plugin>

Then you have to add a lombok.config file in the src folder of your project (not in the resources folder)

lombok.config:

# tells Lombok that this is the root directory and that it shouldn’t search parent directories for more configuration files
config.stopBubbling = true
# tells Lombok to add @lombok.Generated annotation to all generated methods
lombok.addLombokGeneratedAnnotation = true