简体   繁体   English

为什么 Maven 命令“mvn sonar:sonar”在我的“pom.xml”中没有任何插件配置的情况下工作?

[英]Why does the Maven command “mvn sonar:sonar” work without any plugin configuration in my “pom.xml”?

I have a Maven web project in my repo.我的仓库中有一个 Maven Web 项目。

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.我是一个 Maven 菜鸟,但我仍然理解这样一个事实,即我们需要配置一些插件,然后我们才能运行插件特定的命令。

Facts:事实:

I have a sonar server running on my local machine at port 9000.我有一个声纳服务器在我的本地机器上运行,端口为 9000。

I have not added any sonar specific plugin in my POM.xml我没有在 POM.xml 中添加任何声纳特定插件

Reference:参考:

http://www.sonarsource.org/we-had-a-dream-mvn-sonarsonar/ 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.但是当我从命令行在我的项目中运行mvn sonar:sonar ,它仍然可以正常工作。

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?事实是我还没有在我的 POM.xml 中配置声纳插件即使这样 Maven 是从哪里获取并理解“声纳:声纳”目标/命令的?

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我想知道为什么mvn sonar:sonar在没有在我的 pom.xml 中配置声纳插件的情况下工作

WHY and how?为什么和如何?

The reason is that the Sonar Maven Plugin is hosted at the Codehaus Mojo project and benefits from the groupId "org.codehaus.mojo".原因是 Sonar Maven 插件托管在Codehaus Mojo 项目中,并受益于 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 )这允许使用快捷方式“sonar:sonar”而不是“org.codehaus.mojo:sonar-maven-plugin::sonar”(参见Maven 文档的“配置 Maven 以搜索插件”部分)

Sonar has its own set of plugins (eg maven-checkstyle-plugin) which it is running when being invoked. Sonar 有它自己的一组插件(例如 maven-checkstyle-plugin),它在被调用时运行。 These plugins are automatically configured according to your project settings in your configured Sonar server.这些插件会根据您在配置的 Sonar 服务器中的项目设置自动配置。

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).它自动为您工作的原因是您正在使用声纳服务器安装的默认值 (localhost:9000)。

This 'zero-configuration' approach is further detailed here: We had a dream : mvn sonar:sonar这种“零配置”方法在这里有更详细的说明:我们有一个梦想:mvn sonar:sonar

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.我可能是错的,但我的假设是此功能通常来自您的settings.xml而不是我们的pom.xml文件与 Maven。 I would assume that the <id>sonar</id> section specifies the name of the profile invoked when running mvn .我假设<id>sonar</id>部分指定运行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.这只是一个猜测,而不是此时的明确答案,因为其他答案似乎没有达到目标,我目前没有时间深入研究真正的答案。

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.我可能是错的,但我的假设是此功能通常来自您的settings.xml而不是我们的pom.xml文件与 Maven。 I would assume that the <id>sonar</id> section specifies the name of the profile invoked when running mvn .我假设<id>sonar</id>部分指定运行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:参考:

As per this page - https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-maven/根据此页面 - https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-maven/

Maven project scanner uses the SonarScanner by default. Maven 项目扫描器默认使用 SonarScanner。 So it works without any set up.所以它无需任何设置即可工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM