Sonar-scanner or mvn sonar:sonar which one is better

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
  • what are you trying to achieve
  • what have you tried so far to achieve this

Currently I am working on project where I have to perform code coverage and update it on sonarqube.
As I was exploring we can do it via 2 ways

  1. sonar-scanner by adding configuration in
  2. mvn sonar:sonar -----> it will pick data from pom.xml

I am able to complete my task with both steps. But I am still not clear about which approach is better?
Or when basically should I choose sonar-scanner or mvn sonar?

Kindly help me in resolving this query.

If you’re already building a Maven application, you should definitely use the Maven goal. Why respecify things that are already implicit in the pom.xml?

Also note that since most builds are spawned from Jenkins or higher-level build systems, it’s generally better to avoid the use of properties files to provide the additional parameters. You’ll end up constructing a command line, either for “sonar-scanner” or “mvn sonar:sonar”, and it’s more effective to provide the additional parameters right on the command line, instead of a separate file. That practice makes build logs more self-documenting and clear.