Maven SonarQube Multimode Module

I have a project consisting of several modules.

I am trying to analyze them using SonarQube.

I have included the Sonar Maven plugin as a dependency in each module:

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

Then I start Maven using:

mvn net sonar test: sonar

Maven completes successfully, and I see that sonar analysis is happening, however, when I open the Sonar user interface, the modules are not visible in the projects.

But...

If I run the Maven command from a separate module directory, it is visible in projects.

Feel that I am missing something very simple, appreciate any help!

+5
source share
2 answers

Instead of being dependent, put sonar-maven-plugin in the <build> section of the pom.xml root as follows:

 <build> <plugins> <plugin> <groupId>org.sonarsource.scanner.maven</groupId> <artifactId>sonar-maven-plugin</artifactId> <version>3.0.1</version> </plugin> </plugins> </build> 

And since this is a multi-module project, you must first install from the root project and then run the sonar:sonar target as a highlighted step , as follows:

 mvn clean install mvn sonar:sonar 

To configure the sonarqube server URL, specify the sonar.host.url project sonar.host.url in settings.xml or pom.xml as follows:

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

SonarQube supports multi-module projects, as Maven does. This means that a Maven project containing multiple modules displays a SonarQube project containing several modules / components rather than multiple projects.

Take the SonarQube code, for example (this is a multi-module Maven project): the parent project combines all the information with the submodule, then if you check its structure (or its code page) you can see a list of all subcomponents (for example: SonarQube :: Core )

The bottom line is that you see the expected behavior. Maven project submodules are not designed to be analyzed as projects, you should always analyze the parent project, and SonarQube will process the modules initially.

0
source

Source: https://habr.com/ru/post/1246508/


All Articles