Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude files for sonar coverage using terminal command for running sonarqube?

Tags:

java

sonarqube

I am writing generic code for an application which should support multiple country-specific changes, e.g, Brazil and France.

There are some java classes in Brazil which are not required for France. Hence for running the sonarqube, I need to exclude those files for sonar coverage. Also, I would need to exclude dtos, util classes.

We usually exclude the coverage for the classes in the pom file using tag. But I would be requiring to exclude the files with mvn clean install command.

Traditional approach:

enter image description here

But I want to exclude the java classes in the terminal like below:

C:\Projects\web-application>mvn clean install -Dspring.profiles.active=dev -Dspring.profiles.country=brazil -Dsonar.coverage.exclusions=**/pom.xml,**/domain/dtos/**/*,**/domain/models/**/*,**/services/someClass.java

Sonarqube runs but unable to exclude the files.

like image 232
viveknaskar Avatar asked Nov 16 '22 12:11

viveknaskar


1 Answers

I'm assuming You are using In Your params:

-Dsonar.coverage.exclusions=**/pom.xml,**/domain/dtos/**/*,**/domain/models/**/*,**/services/someClass.java

You are mixing path and file exclusions which can cause problems, as mentioned here by Sonar Dev - https://community.sonarsource.com/t/sonar-coverage-exclusions-not-excluding-too-much/31276/4

This should work:

-Dsonar.coverage.exclusions=**/pom.xml,**/domain/dtos/**/*.*,**/domain/models/**/*.*,**/services/someClass.java
like image 111
Xupi Avatar answered Feb 09 '23 01:02

Xupi