Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Sonar and Maven multilevel modules?

Tags:

sonarqube

I encounter issue to configure a multilevel maven modules for Sonar Analysis.

It is working fine with the following structure:

parent module
  |- level 1
       |- module with code to analyze

But if I add a depth to the module with code to analyze, I'm not able to configure it.

parent module
  |- level 1
       |- level 2
           |- module with code to analyze

I tried several configurations:

  1. with no special configuration: I get an Can not execute SonarQube analysis: The project 'level 2' is already defined in SonarQube but not as a module of project 'level 1'. If you really want to stop directly analysing project 'level 2', please first delete it from SonarQube and then relaunch the analysis of project 'level 1'. error. I don't want to launch on level 1 because I have my integration tests at the same level, directly in parent module.
  2. using skippedModules property on level 1 and level 2: Only the parent module is analyzed.
  3. using includedModules by specifying "module with code to analyze": Only the parent module is analyzed.

Does someone has an idea on how to handle it? (I mean without to modifying the hierarchy folder which is really helpful for some other requirements)

Thanks by advance

like image 906
Aurélien Pupier Avatar asked Nov 01 '22 06:11

Aurélien Pupier


2 Answers

I found a workaround: - I launch mvn clean install on parent project - then I launch sonar:sonar at 'level 2' module, I can do it because all the code source to be analyzed is under the same module.

At least it is working on my sample project but currently I didn't handle yet to make it working on my real project.

like image 137
Aurélien Pupier Avatar answered Dec 28 '22 18:12

Aurélien Pupier


Building my Maven multi-module project is consistently working for me. I'm using SonarQube v4.3.

I placed a sonar-project.properties file at the root level of the parent Maven project.

Here's the contents:

# Root project information
sonar.projectKey=<I used the project pom's groupId + artifactId>
sonar.projectName=<can be anything>
sonar.projectVersion=<I used the project pom's version>

# Some properties that will be inherited by the modules
sonar.sources=src

In my parent project's pom, I declared this property:

<sonar.language>java</sonar.language>

Within the same pom, I declared the following:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>2.2</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

I'm building only the parent project, which results in the parent and all of its children getting analyzed by SonarQube. I'm using:

mvn clean install sonar:sonar

or

mvn sonar:sonar
like image 26
Chris Harris Avatar answered Dec 28 '22 18:12

Chris Harris