/sonar-jacoco-lombok-example

Example on how to configure Lombok with JaCoCo and SonarQube to get meaningful coverage results

Primary LanguageJavaMIT LicenseMIT

Build and scan, with no particular configuration to avoid Lombok side effects

Run: mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install org.jacoco:jacoco-maven-plugin:report sonar:sonar

(JaCoCo and) SonarQube report:

  • 100% Line coverage (4/4)
  • 5.5% Condition coverage (1/18)
  • 22.7% overall coverage (5/22)

Specific configuration to avoid Lombok side effects

Change lombok.config.sample file into lombok.config (File contains lombok.addLombokGeneratedAnnotation = true)

Run again: mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install org.jacoco:jacoco-maven-plugin:report sonar:sonar

(JaCoCo and) SonarQube report:

  • 100% Line coverage (1/1)
  • 50% Condition coverage (1/2)
  • 66.6% overall coverage (2/3)

This looks much more meaningful

Corner case: No code outside of lombok generated code

If you class does not contain any code except the lombok generated code (unlikely but who knows...) the effect of ignoring lombok code will yield a special result. The jacoco.xml file is present and mentions the Person.java file, but with no lines to cover. As a result SonarQube will display no coverage information (which is different from 0% coverage)

Corner case: Unit tests that test the lombok generated code

When setting lombok.addLombokGeneratedAnnotation = true the coverage generated by such unit tests will not be taken into account. But anyway, when setting lombok.addLombokGeneratedAnnotation = false the coverage relates to lines that do not exist in the source codes so the results are not any better.