I have a project made up of several modules.
I'm trying to analyse these with SonarQube.
I've 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'm running Maven using:
mvn clean verify sonar:sonar
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.
However...
If I run the Maven command from an individual module directory, it is visible in projects.
Feel I'm missing something very simple, appreciate any help!
Instead of as a dependency, put the
sonar-maven-plugin
in the<build>
section of the rootpom.xml
, as follows: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:To configure the sonarqube server URL, specify a project property of
sonar.host.url
in yoursettings.xml
orpom.xml
as follows: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.
Take SonarQube code for example (it's a multi-module Maven project): the parent project aggregates all info from sub-modules, then if you check its structure (or its code page) you can see the list of all sub-components (for example: 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.