0

Basically sonarqube is using jacoco for code coverage. But I want to exclude few classes from coverage. As per few docs I am using mentioned below plugin in the pom.

          <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <excludes>
                    <exclude>
                        src/main/java/org/sample/SampleRepository.java
                    </exclude>
                </excludes>
            </configuration>
        </plugin>

Sadly it is not working. Need help for that.

Sam
  • 79
  • 1
  • 12

1 Answers1

0

The question is, do you want to generally exclude it in the jacoco report, or is it enough to just not show it on Sonarqube? As for sonarqube you can control it with an additional analysis parameter called sonar.coverage.exclusions.

This parameter can be provided via scanner configuration sonar.coverage.exclusions (ideal solution, as it can be persisted with history in the SCM) or via UI: enter image description here

This might only solve the detection within SonarQube - but it might be enough, depending on your case.

Simon Schrottner
  • 4,146
  • 1
  • 24
  • 36
  • Thanks Simon for the response. Actually locally when I am running code coverage, average coverage is coming very low so I want to exclude/skip those classes which do not required to me(for example Config/Repository classes). Answer to your question is exclude those classes from jacoco report. – Sam Feb 17 '21 at 07:41
  • just a sidenote: i am not sure if during local development the average coverage is that important. The coverage of your feature is important and of your tests you are working on (also coverage overall is a highly discussed topic - mutation testing is interesting here). – Simon Schrottner Feb 17 '21 at 07:50
  • You are right for local development test coverage is not so important. As I am new to this, I want to learn those topics. If I am ignoring this part as of now could you please suggest me where to add "sonar.coverage.exclusions" property? or It would be very helpful if you can provide me example of this property. – Sam Feb 17 '21 at 07:59
  • thats not that easy to answer ;) depends on the scanner you are using. is it the maven scanner, or a standalone scanner? https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/ will for sure point you into the right direction – Simon Schrottner Feb 17 '21 at 08:50