I'm using Gradle sonarqube plugin and I need to exclude all test sources from the sonar analysis (main goal is to filter out unit test classes from the issues/code smells report)
To do so, I have used the dedicated sonar.test.exclusions
property as follow, to exclude the whole src/test
directory from analysis
sonarqube {
properties {
property("sonar.exclusions" , "")
property("sonar.test.exclusions" , "src/test/**/*.java")
// other sonar properties, omitted
}
}
This works as expected (test sources are filtered out) BUT : when this property is set, sonar does not compute/report number of unit tests correctly.
See simple example for a very basic project: 2 main source files, 1 test source file containing 2 Junit tests (and also containing some issues I don"t want to see in report)
- Without exclusions:
Sonar properly reports my 2 unit tests, but it also includes code smells from the unit test class
- With exclusions:
Now, code smells from the unit test are properly filtered, but I lost the Unit test count information
Notes:
- using Gradle 6.7, sonarqube plugin version 3.0, and sonar server
Community EditionVersion 8.4.2
- also tried with the property
sonar.exclusions
: same problem - all other sonar properties are correctly set and have same values in both scenarios : specially
sonar.tests
,sonar.java.test.binaries
,sonar.junit.reportPaths
,sonar.jacoco.reportPath
Any idea how to configure the sonarqube plugin, to exclude properly test sources, while keeping Unit tests information available?