Maven SonarQube多模块

问题描述 投票:8回答:2

我有一个由几个模块组成的项目。

我正试图用SonarQube分析这些。

我在每个模块中都包含了Sonar Maven插件作为依赖项:

<dependency>
  <groupId>org.codehaus.sonar</groupId>
  <artifactId>sonar-maven-plugin</artifactId>
  <version>5.1</version>
</dependency>

然后我使用以下方式运行Maven:

mvn clean verify声纳:声纳

Maven成功完成,我可以看到Sonar分析正在发生,但是当我打开Sonar UI时,模块在项目中不可见。

然而...

如果我从单个模块目录运行Maven命令,它在项目中可见。

觉得我错过了很简单的东西,感谢任何帮助!

java maven sonarqube
2个回答
8
投票

而不是作为依赖,将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>

因为它是一个多模块项目,你应该first perform an install from the root project and then run the sonar:sonar goal as a dedicated step,如下:

mvn clean install
mvn sonar:sonar

要在specify a project property of sonar.host.urlsettings.xml中配置sonarqube服务器URL pom.xml,如下所示:

<properties>
    <!-- Optional URL to server. Default value is http://localhost:9000 -->
    <sonar.host.url>http://myserver:9000</sonar.host.url>
</properties>

2
投票

SonarQube支持多模块项目,就像Maven一样。这意味着包含多个模块的Maven项目映射到包含多个模块/组件的SonarQube项目,而不是多个项目。

以SonarQube代码为例(它是一个多模块Maven项目):parent project聚合子模块中的所有信息,然后如果你检查它的structure(或它的code页面),你可以看到所有子组件的列表(例如:SonarQube::Core

最重要的是你看到了预期的行为。 Maven项目的子模块不打算作为项目进行分析,您应该始终分析父项目,SonarQube将本地处理模块。

© www.soinside.com 2019 - 2024. All rights reserved.