Multi module Scala project gives 0% sonar code coverage

296 views Asked by At

I am using SonarQube Enterprise EditionVersion 7.9.1. I am running maven goal for my multi-module scala project as :

mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent verify org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar

After successfull completion, I am getting 0% code coverage. Below is my sonar.properties:

sonar.junit.reportsPath=target/surefire-reports
sonar.surefire.reportsPath=target/surefire-reports
sonar.jacoco.reportPath=target/coverage-reports/jacoco-unit.exec
sonar.binaries=target/classes
sonar.java.coveragePlugin=jacoco
sonar.verbose=true

Below is pom.xml

    <modules>
        <module>1</module>
        <module>2/module>
        <module>3</module>
        <module>4</module>
    </modules>
   <properties>
        <!-- Sonar -->
        <sonar.version>3.7.0.1746</sonar.version>
        <jacoco.version>0.7.9</jacoco.version>
        <sonar.projectName>ds</sonar.projectName>
        <sonar.projectDescription>**</sonar.projectDescription>
        <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
        <sonar.jacoco.reportPaths>${project.build.directory}/jacoco.exec</sonar.jacoco.reportPaths>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        <sonar.language>scala</sonar.language>
        <sonar.sources>src/main</sonar.sources>
        <!--<sonar.tests>src/test</sonar.tests> -->
        <scoverage.plugin.version>1.4.1</scoverage.plugin.version>
        <sonar.scala.scoverage.reportPath>target/scoverage.xml</sonar.scala.scoverage.reportPath>
        <junit.version>4.11</junit.version>
        <!-- Sonar -->
        
    </properties>
    
    

    <profiles>
        
        <!-- Sonar -->
        <profile>
            <id>coverage-per-test</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.8.7</version>
                            <executions>
            
                            <execution>
                                <id>prepare-agent</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                            </execution> 
                            <execution>
                                <id>report</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>report</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>post-unit-test</id>
                                <phase>test</phase>
                                    <goals>
                                        <goal>report-aggregate</goal>
                                    </goals>
                                    <configuration>
                                        <!-- Sets the path to the file which contains the execution data. -->
                                        <dataFile>target/jacoco.exec</dataFile>
                                        <!-- Sets the output directory for the code coverage report. -->
                                        <outputDirectory>target/jacoco-ut</outputDirectory>
                                    </configuration>
                            </execution>
                        </executions>
                        <configuration>
                <systemPropertyVariables>
                            <jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
                </systemPropertyVariables>
 </configuration>
                    </plugin>
                </plugins>
                </build>
            
        </profile>
        <!-- Sonar -->
        
    </profiles>

    
</project>

I am getting the coverage as 0%, when there are many unit test written. How should I fix this?

0

There are 0 answers