After several hours of online research including this forum, I am writing here to have a better understanding about Java code coverage with sonarqube and possibly find answers to some of my questions.
Before I start, my env consists of
- Java 17 springboot applications
- Jacoco maven plugin v0.8.7
- Sonar maven plugin v3.9.0
- Sonarqube Enterprise Edition v9.9.4
So as I understand, the code coverage is generated by Jacoco after unit tests and the report is transferred to sonarqube server by sonar maven plugin. While I am excluding some files from jacoco coverage report (checking locally from target/site/jacoco/index.html
) by adding a exclude list under pom.xml > build > plugin > jacoco > configuration > excludes
, I am also having a sonar.coverage.exclusions
with the same files/classes.
Out of the above, I am trying to clarify the followings:
-
I am assuming the jacoco exclusion list is not accountable while building sonarqube code coverage. This is because the jacoco.exec / jacoco.xml is imported by sonarqube server and processed on its own to generate the code coverage % out of raw test result data.
-
Is there any way to use Java class annotations to mark code coverage exclusions inline in Java source code? I read somewhere about
@Generated
and some custom annotations but not too sure if that can be used for code coverage exclusion rather issue suppression?