javaspring-bootmavensonarqubemaven-surefire-plugin

Getting 0% Sonar coverage, jacoco.xml not generated


This is how my POM file looks like:

<properties>
        <java.version>11</java.version>
        <spring-cloud.version>3.1.5</spring-cloud.version>
        <jacoco.version>0.8.6</jacoco.version>
        <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        <sonar.version>3.4.0.905</sonar.version>
        <swagger.version>3.0.0</swagger.version>
        <sonar.host.url>http://localhost:9000</sonar.host.url>
        <sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
    </properties>
<plugin>
                <groupId>org.sonarsource.scanner.maven</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>${sonar.version}</version>
            </plugin>
<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>${jacoco.version}</version>
    <executions>
        <execution>
            <id>jacoco-initialize</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>jacoco-site</id>
            <phase>package</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
    </executions>
</plugin>

enter image description here

enter image description here

the coverage was coming 70% before, but it is coming as 0 after updating the versions of spring boot , sonar and jacoco. I have written the test cases. Sure fire reports are getting generated but I don't see jacoco.xml though jacoco.exec is generating

enter image description here

enter image description here


Solution

  • This worked for me:

    1. Run mvn clean install (check if jacoco.exec is generated in the target folder).
    2. Then run mvn jacoco:report (This will generate the jacoco.xml file which sonar will import and calculate the coverage)