Directories/files not being excluded from SonarQube coverage report

SonarQube Developer Edition Version 9.2.4 (build 50792)

I am trying to exclude a directory of files from SQ code coverage reports but they are still included in the coverage reports for master and PR branches. This is a problem because I have a quality gate that includes test coverage.

From project properties (in SonarQube UI) for sonar.coverage.exclusions
upgrade/**/*,lib/postgres.js

From SonarQube log:

22:34:42  INFO: Project configuration:
22:34:42  INFO:   Excluded sources: **/node_modules/**, coverage/**, **/test/**, testc/**, testb/**, testwo/**, routesb/**, routeswo/**, doc/**, .idea/**, .migration/**, .portal/**, **/*.yaml, **/*.yml, **/*.json, **/*.html, **/*.htm, **/*.sql, routes/integration.js
22:34:42  INFO:   Excluded sources for coverage: upgrade/**/*,lib/postgres.js
22:34:43  INFO: 444 files indexed
22:34:43  INFO: 28177 files ignored because of inclusion/exclusion patterns
22:34:43  INFO: 0 files ignored because of scm ignore settings

Directories/files I want to exclude:
upgrade/upgrade.js
upgrade/steps/1/
upgrade/steps/2/

upgrade/steps/75/

Observed behaviour:

  1. PR with new code in upgrade/steps/75/ failed SonarQube Quality Gate
    ‘0.0% Coverage on New Code (is less than 70%)’

  2. SonarQube UI shows lots of files under upgrade/ with low coverage, including upgrade.upgrade.js and lib/postgres.js which is also on the exclude list
    https://<my_server>/component_measures?id=velox%3Aapim&metric=coverage&view=list

Hopefully I am just doing something wrong. Help appreciated.
I have some settings in sonar-project.properties file, but not sonar.coverage property.
I am adding that now to see if it makes any difference.

Adding this to sonar-project.properties has worked:

sonar.coverage.exclusions=lib/webhookUtil.js,upgrade/*,upgrade/**,lib/postgres.js

I don’t know if it because of separating upgrade/*,upgrade/** or maybe putting it in sonar-project.properties.
Will try setting the same exclusions value in project settings in SonarQube UI

How are SonarQube properties in SonarQube server (global vs. project) vs. properties in project’s sonar-project.properties file resolved?
Is there an order of precedence between properties in the 3 locations?
If a property is set if 1 of the 3 places, is its value used?

I would prefer to set most properties in the UI but keep still keep some stuff in sonar-project.properties file.

thanks.

After a few experiments, it looks like setting sonar.coverage.exclusions only in the SonarQube ui / project properties does not work. The SonarScanner log says that the setting was picked up but the files are still included in coverage.

15:46:21  15:46:21.440 INFO:   Excluded sources: **/node_modules/**, coverage/**, **/test/**, testc/**, testb/**, testwo/**, routesb/**, routeswo/**, doc/**, .idea/**, .migration/**, .portal/**, **/*.yaml, **/*.yml, **/*.json, **/*.html, **/*.htm, **/*.sql, routes/integration.js
15:46:21  15:46:21.441 INFO:   Excluded sources for coverage: lib/noSuchUI,upgrade/*,upgrade/**,lib/postgres.js
15:46:21  15:46:21.569 DEBUG: 2412 non excluded files in this Git repository

15:46:21  15:46:21.744 DEBUG: Average line length for lib/postgres.js is 95
15:46:21  15:46:21.744 DEBUG: 'lib/postgres.js' indexed with language 'js'

No log message saying the file is excluded for coverage.

But setting the property (only) in sonar-project.properties files does take effect

17:00:57  17:00:57.278 INFO:   Excluded sources: **/node_modules/**, coverage/**, **/test/**, testc/**, testb/**, testwo/**, routesb/**, routeswo/**, doc/**, .idea/**, .migration/**, .portal/**, **/*.yaml, **/*.yml, **/*.json, **/*.html, **/*.htm, **/*.sql, routes/integration.js
17:00:57  17:00:57.279 INFO:   Excluded sources for coverage: lib/noSuchProps, upgrade/*, upgrade/**, lib/postgres.js
17:00:57  17:00:57.461 DEBUG: 2412 non excluded files in this Git repository

17:00:58  17:00:57.972 DEBUG: Average line length for upgrade/steps/10/dataUpgrade.js is 32
17:00:58  17:00:57.972 DEBUG: 'upgrade/steps/10/dataUpgrade.js' indexed with language 'js'
17:00:58  17:00:57.972 DEBUG: File upgrade/steps/10/dataUpgrade.js excluded for coverage

Hi,

I’m glad you worked through this. To answer your question, parameter precedence is explained here.

 
HTH,
Ann