I have a Java Multi maven project and I configured Jacoco maven plugin for each submodule to exclude files I don't want coverage report for. I though I succeeded as I don't see these files I've excluded in the html report generated by jacoco. I assumed these class files were excluded from the jacoco.exec files. Now I consume these accumulated jacoco.exec files in SonarQube and I see coverage of all submodules however when I entered inside the class details I saw again the classes I defined to exclude. So I had to define AGAIN these exclusions with sonar.exclusions property in order not to see them in sonar.
For jacoco:
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*JavaProjectApiModule.class</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
For Sonar I configured in the parent pom.xml, in the properties secion:
<sonar.exclusions>
**/JavaProjectApiAModule.java
</sonar.exclusions>
I thought once I exclude them using jacoco configuration, they will not be added to the jacoco.exec files and in turn will not show up in sonar.. But now it seems I will have to maintain the exclusions both for jacoco AND sonar configurations and it will be a big mess in case of classes from different modules...
Am I missing something here? Is this the way? to maintain exclusions for jacoco separated from sonar?
Thanks in advance!
sonar.exclusions
parameter defines which files should be ommit by the scanner. It means that those files won't be displayed in SonarQube.
Files excluded from JaCoCo reports are skipped by JaCoCo agent during tests execution.
When the scanner scans files which are not included in JaCoCo report then they are displayed in SonarQube but without code coverage information. When the scanner ignores files (their paths match sonar.exclusions
) then they are not displayed in SonarQube - no matter if they are included in JaCoCo report or not.