Why does the Maven command "mvn sonar:sonar" work without any plugin configuration in my "pom.xml"?

JavaMavenSonarqubeMaven Plugin

Java Problem Overview


I have a Maven web project in my repo.

I am a Maven noob but still I understand the fact that there are plugins which we need to configure only then we could run plugin specific commands.

Facts:

I have a sonar server running on my local machine at port 9000.

I have not added any sonar specific plugin in my POM.xml

Reference:

http://www.sonarsource.org/we-had-a-dream-mvn-sonarsonar/

Observation:

But still when I run mvn sonar:sonar in my project from command line it works fine.

Matter of the fact is I have NOT configured sonar plugin in my POM.xml Even then from where the hell Maven is picking up and understanding "sonar:sonar" goal/command?

Question / curiosity:

I don't want the working knowledge of sonar itself. I want to know why mvn sonar:sonar works without configuring a sonar plugin in my pom.xml

WHY and how?

Java Solutions


Solution 1 - Java

The reason is that the Sonar Maven Plugin is hosted at the Codehaus Mojo project and benefits from the groupId "org.codehaus.mojo". This allows to use the shortcut "sonar:sonar" instead of "org.codehaus.mojo:sonar-maven-plugin::sonar" (see the section "Configuring Maven to Search for Plugins" of the Maven documentation)

Solution 2 - Java

Sonar has its own set of plugins (e.g. maven-checkstyle-plugin) which it is running when being invoked. These plugins are automatically configured according to your project settings in your configured Sonar server.

The reasoning behind this to have a controlled configuration in your sonar instance.

The reason it is working automatically for you is that you are using the default values for your sonar server installation (localhost:9000).

This 'zero-configuration' approach is further detailed here: We had a dream : mvn sonar:sonar

Solution 3 - Java

I could be wrong but my assumption is that this capability typically comes from your settings.xml instead of our pom.xml file with Maven. I would assume that the <id>sonar</id> section specifies the name of the profile invoked when running mvn.

This is merely a guess as opposed to a definitive answer at this time as other answers seemed to be missing the mark and I don't have the time to dig into the real answers myself at the moment.

Solution 4 - Java

I could be wrong but my assumption is that this capability typically comes from your settings.xml instead of our pom.xml file with Maven. I would assume that the <id>sonar</id> section specifies the name of the profile invoked when running mvn.

This is merely a guess as opposed to a definitive answer at this time as other answers seemed to be missing the mark and I don't have the time to dig into the real answers myself at the moment.

References:

Solution 5 - Java

As per this page - https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-maven/

Maven project scanner uses the SonarScanner by default. So it works without any set up.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRakesh WaghelaView Question on Stackoverflow
Solution 1 - JavaSimon Brandhof - SonarSourceView Answer on Stackoverflow
Solution 2 - JavaTorstenView Answer on Stackoverflow
Solution 3 - JavajpiersonView Answer on Stackoverflow
Solution 4 - JavajpiersonView Answer on Stackoverflow
Solution 5 - JavaRamesh RRView Answer on Stackoverflow