Code coverage is calculated wrong with default maven sources

Using SonarQube 7.9:

Using the sonar maven plugin the code coverage is only calculated for the code in src/main/java, but not for the generated code in target/generated-sources/annotations.

For me this means the code coverage metric is wrong because all the code that is included in the build artifact should be considered to calculate the code coverage independent if it is manual or generated code.

We use the following configuration now:


The second one is needed to ignore code duplication in generated code.
The third one is needed as the target directory is normally part of the .gitignore file.

It would improve the out of the box experience with sonar if this would be handled correctly.

Kind regards,

Hi Michael,

As a clarification, your title is “…with default maven sources”. Does that mean that with these settings, coverage is calculated as you expect?

And if not, with these settings do you see the generated files otherwise treated as normal source code?



By this I mean the sources that are considered by default from the sonar maven plugin. They do not include the generated sources, so without any adjustments as described above, the calculated code coverage is to optimistic.

Kind regards,

Hi Michael,

Thanks for clarifying.

Our standard recommendation is that you should exclude generated code from analysis, so we won’t be changing this behavior.

Thanks for understanding.


For analysis of issues this behavior is totally ok, but in my opinion not for code coverage. Would be interested in opinions of other sonarqube users.