java Maven SonarQube 多模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36438281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven SonarQube multi module
提问by timothyclifford
I have a project made up of several modules.
我有一个由几个模块组成的项目。
I'm trying to analyse these with SonarQube.
我正在尝试用 SonarQube 分析这些。
I've included the Sonar Maven plugin as a dependency in each module:
我在每个模块中都包含了 Sonar Maven 插件作为依赖项:
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>5.1</version>
</dependency>
Then I'm running Maven using:
然后我使用以下命令运行 Maven:
mvn clean verify sonar:sonar
mvn clean 验证声纳:声纳
Maven completes successfully and I can see the Sonar analysis happening however when I open the Sonar UI, the modules aren't visible in projects.
Maven 成功完成,我可以看到发生的声纳分析,但是当我打开声纳 UI 时,这些模块在项目中不可见。
However...
然而...
If I run the Maven command from an individual module directory, it is visible in projects.
如果我从单个模块目录运行 Maven 命令,它在项目中是可见的。
Feel I'm missing something very simple, appreciate any help!
感觉我错过了一些非常简单的东西,感谢任何帮助!
采纳答案by heenenee
Instead of as a dependency, put the sonar-maven-plugin
in the <build>
section of the root pom.xml
, as follows:
而不是作为依赖,把 放在根sonar-maven-plugin
的<build>
部分pom.xml
,如下所示:
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.0.1</version>
</plugin>
</plugins>
</build>
And since it's a multi-module project, you should first perform an install from the root project and then run the sonar:sonar
goal as a dedicated step, as follows:
由于它是一个多模块项目,您应该首先从根项目执行安装,然后将sonar:sonar
目标作为专用步骤运行,如下所示:
mvn clean install
mvn sonar:sonar
To configure the sonarqube server URL, specify a project property of sonar.host.url
in your settings.xml
or pom.xml
as follows:
要配置 sonarqube 服务器 URL,请在您的或 中指定项目属性,sonar.host.url
如下所示:settings.xml
pom.xml
<properties>
<!-- Optional URL to server. Default value is http://localhost:9000 -->
<sonar.host.url>http://myserver:9000</sonar.host.url>
</properties>
回答by Nicolas B. - SonarSource Team
SonarQube supports multi-module projects just like Maven does. This means that a Maven project containing multiple modules maps to a SonarQube project containing multiple modules/components, not multiple projects.
SonarQube 像 Maven 一样支持多模块项目。这意味着包含多个模块的 Maven 项目映射到包含多个模块/组件的 SonarQube 项目,而不是多个项目。
Take SonarQube code for example (it's a multi-module Maven project): the parent projectaggregates all info from sub-modules, then if you check its structure(or its codepage) you can see the list of all sub-components (for example: SonarQube::Core)
以 SonarQube 代码为例(它是一个多模块 Maven 项目):父项目聚合来自子模块的所有信息,然后如果您检查其结构(或其代码页),您可以看到所有子组件的列表(例如示例:SonarQube::Core)
The bottom line is that you're seeing expected behaviour. Sub-modules of a Maven project are not meant to be analysed as projects, you should always analyse the parent project and SonarQube will handle modules natively.
底线是您看到了预期的行为。Maven 项目的子模块不打算作为项目进行分析,您应该始终分析父项目,SonarQube 将在本机处理模块。