A_M
A_M

Reputation: 7851

Sonarqube gradle plugin coverage with Lombok

I have a class annotated with Lombok's @Data, in a gradle project, using the Sonarqube and Jacoco plugins.

The source code is available here on github

I have a locally running sonarqube server running as a docker container, started like this:

docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 sonarqube  

I have added a "lombok.config" file, asking it to add @Lombok.Generated annotations to its generated code, as per the Global Config keys section here in the docs.

lombok.addLombokGeneratedAnnotation = true

And I have the following Sonar condition configuration.

enter image description here

When I run the sonarqube target for the very first time, it reports that the project passes.

enter image description here

If I then switch the lombok.addLombokGeneratedAnnotation to be false, and rerun the sonarqube target, it reports that there is a failure:

enter image description here

If I then switch the lombok.addLombokGeneratedAnnotation back to true, and rerun again, sonarqube reports that the project is still failed. And I can't get the project to pass again.

I then changed the group name in the build.gradle file, to force the sonarqube gradle plugin to create a new project within the Sonarqube server. When I do this, the project passes again.

I've never changed any of the source code during this process.

Please does anyone have an idea why Sonarqube is behaving this way?

Upvotes: 0

Views: 1318

Answers (2)

A_M
A_M

Reputation: 7851

For future reference, we found that the problem was solved by updating the SonarJava plugin to the newest 5.1.1 release.

I think this ticket in release 5.1, to upgrade to Jacoco 0.8.0 may be the thing that started to honour the @Lombok.Generated annotation.

enter image description here

Upvotes: 0

G. Ann - SonarSource Team
G. Ann - SonarSource Team

Reputation: 22804

I've never changed any of the source code during this process.

Oh, but you have. Or rather, Lombok has by inserting (or not) annotations in your code.

You're using a Quality Gate that looks only at "New Code". On your first analysis, no code is new, so none of it is up for consideration. Then you twiddle your Lombok settings, regenerate and reanalyze. Lombok apparently makes some changes in your code. I've never used Lombok so I can't expand on exactly what's happening here, but you can click through on the New Coverage-related metrics on the project homepage to get to a list of files. Drill into a file to see what's being considered "new" in it (yellow highlight). Look to the marginal markings (red, green, yellow striped) to see what's considered covered.

N.B. Your quality gate currently demands 99% coverage on conditions in new code. This is unrealistic and past the point of diminishing returns. You should reconsider this value. IMO 85-95% is more realistic depending on your team.

Upvotes: 3

Related Questions