0

I have a package, com.org.projectname.model, in my project. What I want to do is exclude all the files within this package from SonarQube coverage. I tried, <exclude>**/model /*.class</exclude> and <exclude>**/com/org/projectname/model/*.class</exclude>, but this didn't work.

<plugin>
   <groupId>org.jacoco</groupId>
   <artifactId>jacoco-maven-plugin</artifactId>
   <version>0.8.6</version>
   <configuration>
      <excludes>
      
      </excludes>
   </configuration>
   <executions>
      <execution>
         <id>pre-unit-test</id>
         <goals>
            <goal>prepare-agent</goal>
         </goals>
         <configuration>
            <destFile>target/coverage-data/jacoco-ut.exec</destFile>
            <propertyName>surefireArgLine</propertyName>
         </configuration>
      </execution>
      <execution>
         <id>post-unit-test</id>
         <phase>test</phase>
         <goals>
            <goal>report</goal>
         </goals>
         <configuration>
            <dataFile>target/coverage-data/jacoco-ut.exec</dataFile>
            <outputDirectory>target/coverage-reports/jacoco-ut</outputDirectory>
         </configuration>
      </execution>
   </executions>
</plugin>

How to fix this issue? Or is there any other way?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
ima.technophyle
  • 557
  • 1
  • 5
  • 19
  • 2
    You need to exclude it from SonarQube, not from JaCoCo. See Ignore Code Coverage over [here](https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/). – dan1st Nov 18 '21 at 08:48
  • **/model/ *.class -- there is white space before *.class – newcoder Nov 18 '21 at 09:20
  • 1
    Does this answer your question? [Configure Sonar to exclude files from Maven pom.xml](https://stackoverflow.com/questions/21425012/configure-sonar-to-exclude-files-from-maven-pom-xml) – filpa Nov 18 '21 at 10:07
  • It seems like you edited the [solution by Kris](https://stackoverflow.com/a/70017809/466862) into your question. I have removed it again. – Mark Rotteveel Nov 18 '21 at 16:52

1 Answers1

3

Have you tried using sonar.exclusions in your POM properties?

<properties>
      <sonar.exclusions>
          **/model/*.java
        </sonar.exclusions>
</properties>
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Kris
  • 562
  • 5
  • 17
  • 2
    Was going to write an answer but this is in the right direction. The correct properties would be `sonar.cpd.exclusions` (copy-paste detection) and `sonar.coverage.exclusions` (coverage analysis), however - `sonar.exclusions` would exclude all other kinds of analyses as well which may not be what the author intends. – filpa Nov 18 '21 at 10:05
  • @filpa do we need to have any specific dependency to use ? Because the above solution is not working for me? Still, sonarQube is showing 0% coverage on the specific package that I am trying to exclude. I have modified the code based on all your inputs. – ima.technophyle Nov 18 '21 at 12:04
  • Are you sure that you have declared the properties as top-level properties? How do you actually run the SonarQube analysis? It seems you're missing the `sonar-maven-plugin` plugin - are you running SonarQube separately from your build process? In that case, you may need to add the above properties as system properties or using `sonar-project.properties` (on a per-project basis, probably not the best way unless you have specific needs in various projects). – filpa Nov 18 '21 at 16:41