Sonar-project.properties and maven sonar:sonar goal

Hi
I am scanning code using sonar:sonar maven goal.
I have to exclude certain files from sonar scannig. I can do this using property sonar.exclusions. (e.g. sonar.exclusions=/my-pkg//*)

Now my questions are how can I pass property to sonar:sonar?
I have following options
a) use of -Dsonar.exclusions=/my-pkg//* while calling sonar:sonar
b) use of <sonar.exclusions>/my-pkg//</sonar.exclusions> in pom.xml
c) use of sonar-project.properties and specify sonar.exclusions=/my-pkg//
in it.

I know a) and b) above works. But I am keen to use option c) as it keeps sonar config consolidated and isolated in separate file and dont clutter my pom.xml.
Reading from documentation at https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Maven I am not sure whether options c) works?
(I did tried it but has not worked for me - I am not sure if its my mistake or sonar:sonar does not support it?)

Thus my real question to community is does sonar-project.properties present in project folder work with maven sonar:sonar goal???

Appreciate any help on this.

Many Thanks !
~Preetam

Hi Preetam,

mvn sonar:sonar gets its configurations from the command line (with -Dsonar.x=y parameters) and the pom. It does not read sonar-project.properties.

I’d like to point out that you do have another option for setting these exclusions, which is via the UI, altho I recognize that that doesn’t get you any closer to your goal of “consolidated and isolated” configs.

 
HTH,
Ann

2 Likes

Thanks Ann

Yeah UI is also an option but as you said not suitable for my purpose.

BTW - Thanks for confirming that sonar:sonar does not read sonar-project.properties. I wont try to bother now why it has not worked for me.
This also means I have to choose between -D or pom.xml options based upon my situation.

Anyway …
Many Thanks !
~Preetam

1 Like