[Java_Sonar_Plugin] Lombok and Coverage

1,349 views
Skip to first unread message

antony...@vertoanalytics.com

unread,
Aug 21, 2017, 11:02:10 AM8/21/17
to SonarQube
Hi,

I am having trouble getting the coverage metrics produced by Sonarqube to match those produced by Jacoco.

I don't wish to include Lombok generated code in the coverage measure, Jacoco 0.7.10 (not yet released) includes a feature to exclude this code from coverage stats, and I can see from the Jacoco coverage report that this is working correctly.

However when I run the Sonarqube analysis it is still including these generated code and branches in the coverage measure (specifically generated hashCode and equals methods generate a lot of branches).

It appears that the missed lines and branches produced by Jacoco are being ignored by Sonarqube in favour of it's own computed values.

In some cases a class contains only generated bytecode from Lombok, and the whole class is still included in the coverage metric.

I want this so that our developers concentrate their efforts on covering hand written code, rather than generated code (the former is more likely to find bugs, and the latter is an exercise in yak shaving).

It's not feasible to exclude whole classes when they contain a mixture of generated code and hand written code (which is by far the most common case), it would be great if there was a way to get Sonarqube to honour the lines and branches missed as reported by Jacoco.

Best Regards,
Antony

Tibor Blenessy

unread,
Sep 5, 2017, 12:56:39 PM9/5/17
to antony...@vertoanalytics.com, SonarQube
Hello Antony,

as you mentioned, this filtering feature is only available in not yet released Jacoco 0.7.10. SonarJava, which is the SonarQube plugin responsible for providing Java code coverage, is embedding latest released version of Jacoco 0.7.9. This is why you see the discrepancy.

Once 0.7.10 is released, we will release new version of SonarJava plugin, and filtering should work correctly.

Best regards,

Tibor

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/fb5f72c7-e712-425b-bb08-f89f921f9342%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Tibor Blenessy | SonarSource

SonarJava Developer

http://sonarsource.com 

laura.l...@gfs.com

unread,
Feb 7, 2018, 9:39:43 AM2/7/18
to SonarQube
Hello SonarQube team -

I see that version 5.1 of the SonarJava plugin includes JaCoCo 0.8.0, but there is no mention of ignoring Lombok code.

Now that the plugin is upgraded, does the Lombok filtering work? I ask because I found this StackOverflow post indicating that SonarQube reads .exec files, not report files, so unless SonarQube adjusted the JaCoCo handling it will continue to report incorrect results. I searched the SonarQube JIRA instance for related issues and checked release notes but didn't see anything.

Thank you!

Nicolas Peru

unread,
Feb 7, 2018, 11:28:31 AM2/7/18
to laura.l...@gfs.com, SonarQube
Hi, 
Jacoco version was updated in SonarJava  5.1. and filtering should work.
Did you try and have you encountered an actual issue ?

Cheers, 


For more options, visit https://groups.google.com/d/optout.
--
Nicolas Peru | SonarSource

laura.l...@gfs.com

unread,
Feb 7, 2018, 11:45:37 AM2/7/18
to SonarQube
Hi Nicolas,

We are still running SonarQube 6.3 so can't apply version 5.1 of the plugin yet and haven't been able to test. Other than in the SO post, I didn't find any reference to handling Lombok so I wondered if it was one of the test scenarios. Sounds like it was. Thanks for the response!

Nicolas Peru

unread,
Feb 8, 2018, 2:15:57 AM2/8/18
to laura.l...@gfs.com, SonarQube
Hi, 
Just to be crystal clear : 
There was no tests whatsoever regarding lombok and JaCoCo on SonarJava side.
Fact : JaCoCo version with filters was udpated in SonarJava 5.1
To the question : does it work with lombok ? the answer is: in theory it should, in practice, please give a try and let us know if it does not.

Cheers, 


For more options, visit https://groups.google.com/d/optout.

mikae...@gmail.com

unread,
Apr 19, 2018, 11:41:43 AM4/19/18
to SonarQube
To me it does not


Sonar 7
Sonar Jacoco plugin 5.1.1


in src folder (same level as build.gradle)

lombok.config
lombok.addLombokGeneratedAnnotation=true


build.gradle:

jacoco {
toolVersion = "0.8.1"

Nicolas Peru

unread,
Apr 20, 2018, 8:39:44 AM4/20/18
to mikae...@gmail.com, SonarQube
Hi, 

When you say "Sonar 7" I guess you are referencing sonarqube version. 
What matters here is the version of SonarJava installed on your server which should be >= 5.1. Can you please check which version is installed on your server ?

Thanks



For more options, visit https://groups.google.com/d/optout.

Mikael KROK

unread,
Apr 20, 2018, 9:04:26 AM4/20/18
to Nicolas Peru, SonarQube
hi,

You are absolutely right.

Here is my sonarJava version (previously we were on 5.1) 

SonarJavaLanguages
Code Analyzer for Java
  • 5.3 (build 13828)installed


We have added 2 reports for jacoco

target/jacoco.exec
target/jacoco-it.exec





To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages