what are you trying to achieve
I want to specify global team level keys as part of the CI pipeline but with the ability to add to a specific key from the project specific “sonar-project.properties” file.
Example:
Globally our CI can exclude the “main.cpp” for all projects for coverage, thus I want the CI to add --define sonar.coverage.exclusions=src/**/main.cpp to the sonar scanner.
But I still want to be able to add specific other files per project, for example project A might add sonar.coverage.exclusions = src/version.cpp in its properties file.
what have you tried so far to achieve this
From my testing it appears that the command line option passed to sonar-scanner is the only one used. The option in the properties file is ignored/overwritten with the command line option.
Is there a way to support both without relying on each project adding these general files to their properties file?
While something like this is possible for excluding entire files from analysis (sonar.global.exclusions) – nothing like this exists for sonar.coverage.exclusions… and I’m not sure precisely why.
There’s a specific hierarchy where analysis parameters override each other, and no way to say “append” rather than “overwrite”.
What you could imagine doing is setting an environment variable with the global values for sonar.coverage.exclusions (like export GLOBAL_COVERAGE_EXCLUSIONS=src/**/main.cpp) and then have your users reference the environment variable and append any special files. It’s not a perfect solution.