How can I scan a multi module maven project with sonar?

Viewed 1901

I have a multi module maven project and when I try to run a sonar scan only 1 of the 3 modules are ran. I have a parent Pom with the below modules

  <modules>
    <module>core</module>
     <module>Infra</module>
    <module>web</module>
 </modules>

The web module is the only coverage in the scan. It is the same module that contains the main class. What can I do to get all modules?

Edit:

    <!-- Sonar -->
    <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
    <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
    <sonar.jacoco.reportPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPath>
    <sonar.language>java</sonar.language>

I have this above in my parent POMs properties

   <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.9</version>
            <configuration>
                <destFile>${sonar.jacoco.reportPath}</destFile>
                <append>true</append>
            </configuration>
            <executions>
                <execution>
                    <id>agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <propertyName>jaCoCoArgLine</propertyName>
                        <destFile>${sonar.jacoco.reportPath}</destFile>
                    </configuration>
                </execution>
                <execution>
                    <id>report-aggregate</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>report-aggregate</goal>
                    </goals>
                    <configuration>
                        <dataFile>${project.basedir}/target/jacoco-unit.exec</dataFile>
                         <outputDirectory>${project.build.directory}/jacoco-report</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <!-- The configuration seems to be required for test coverage to work -->
            <configuration>
                <argLine>${argLine}</argLine>
            </configuration>
        </plugin>

And this in the parent POM properties.

And here is the command used to run the sonar

   mvn -e org.sonarsource.scanner.maven:sonar-maven-plugin:${config.sonarMavenPluginVersion}:sonar 

  -Dsonar.host.url=${config.sonarHostUrl} 
   -Dsonar.login=${config.sonarLogin} 
1 Answers

This is what I did to get it working:

  1. Added the jacoco plugin as above to the build section of the parent pom

  2. Add the following to my maven settings.xml file (I'm running sonarqube locally):

    <sonar.host.url>http://localhost:9000</sonar.host.url>

    <sonar.login>whatever credential you are using for login token </sonar.login>

  3. Make sure to run a mvn clean install first followed by a mvn sonar:sonar

Related