74

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?

eel ghEEz
  • 1,186
  • 11
  • 24
Rakesh Waghela
  • 2,227
  • 2
  • 26
  • 46

5 Answers5

68

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)

Simon Brandhof
  • 5,137
  • 1
  • 21
  • 28
  • 2
    Still don't get it.. Why does having the groupId "org.codehaus.mojo" let us use the shortcut? – Zhenya Mar 12 '15 at 17:34
  • 3
    @levgen org.apache.maven.plugins and org.codehaus.mojo are special group ids. See the last section of http://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html – Simon Brandhof Mar 13 '15 at 13:25
  • 5
    This does not answer the question as to how `mvn sonar:sonar` executes while the plugin is not mentioned in pom ? I think the OP did not wanted to ask about how `sonar` is resolved. – Number945 May 07 '19 at 07:01
  • 1
    @BreakingBenjamin your question seems to be about Maven itself, but not about SonarQube. – Simon Brandhof May 08 '19 at 08:22
5

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

Torsten
  • 6,184
  • 1
  • 34
  • 31
  • 1
    No, Sonar directly executes the code analyzers like Checkstyle, PMD and Findbugs, without depending on the related Maven plugins. It allows to support non-Maven environments. Moreover for information Sonar embeds its own enhanced code analyzer. – Simon Brandhof Mar 05 '13 at 21:57
  • Thanks for setting this straight Simon. – Torsten Mar 05 '13 at 22:01
0

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.

jpierson
  • 16,435
  • 14
  • 105
  • 149
0

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:

jpierson
  • 16,435
  • 14
  • 105
  • 149
0

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.