CodeCoverage stays at 0.00%

Hey guys,

I am using the newest SonarQube-Version and I can see CodeSmells, Vulnerabilities, and Bugs. But my Coverage stays at 0.00%.

I am using Java 11/Maven.

I already added the Jococo plugin but I still don’t get any Coverage.

My pom.xml looks like this:


4.0.0

<groupId>com.${company-name}.sonar-scanner</groupId>
<!-- it's recommended to follow the pattern "sonar-{key}-plugin", for example "sonar-myphp-plugin" -->
<artifactId>sonar-maven-plugin</artifactId>
<version>1.0</version>

<name>Sonar-Results</name>
<description>Prints the results and marks important numbers</description>

<!-- set file encoding to utf-8 -->
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <sonar.apiVersion>7.1</sonar.apiVersion>
</properties>

<!-- this is important for sonar-packaging-maven-plugin -->
<packaging>sonar-plugin</packaging>

<dependencies>
    <dependency>
        <groupId>org.sonarsource.sonarqube</groupId>
        <artifactId>sonar-plugin-api</artifactId>
        <!-- minimal version of SonarQube to support. -->
        <version>6.7</version>
        <!-- mandatory scope -->
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20190722</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.sonar</groupId>
        <artifactId>sonar-plugin-api</artifactId>
        <version>5.1-RC2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
        <artifactId>sonar-packaging-maven-plugin</artifactId>
        <version>1.18.0.372</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.10</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.7.26</version>
    </dependency>
</dependencies>


<build>
    <plugins>
        <plugin>
            <groupId>org.sonarsource.scanner.maven</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>3.7.0.1746</version>
        </plugin>
        <plugin>
            <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
            <artifactId>sonar-packaging-maven-plugin</artifactId>
            <version>1.18.0.372</version>
            <extensions>true</extensions>
            <configuration>
                <!-- the entry-point class that extends org.sonar.api.SonarPlugin -->
                <pluginClass>SonarResults.Main</pluginClass>
                <pluginDescription>packaging-maven</pluginDescription>
                <!-- advanced properties can be set here. See paragraph "Advanced Build Properties". -->
            </configuration>
        </plugin>
        <!--is up and working we need to add the jacoco maven plugin as shown below.-->
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.5</version>
            <executions>
                <execution>
                    <id>prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Sorry if the pom.xml looks a bit weird it is my first time with maven

+1 here. Cannot get coverage to post with sonar.coverage.jacoco.xmlReportPaths

Hi Mike,

Looking at your configuration, when you run mvn verify or install or deploy, the jacoco-maven-plugin should create the file target/site/jacoco/jacoco.xml. Do you have this file?

Then, if you run mvn -X sonar:sonar you should see log like the following, do you confirm?

[INFO] 16:59:10.201 Sensor JaCoCo XML Report Importer [jacoco]
[INFO] 16:59:10.201 1/1 source files have been analyzed
[DEBUG] 16:59:10.203 Reading report '/home/user/project/target/site/jacoco/jacoco.xml'
[INFO] 16:59:10.208 Sensor JaCoCo XML Report Importer [jacoco] (done) | time=7ms

More info in [Coverage & Test Data] Importing JaCoCo coverage report in XML format

And out of curiosity, what your project is about? Because I see a dependency on org.sonarsource.sonarqube:sonar-plugin-api, do you want to create your own SonarQube plugin? Same question for sonar-packaging-maven-plugin? You don’t need this to run mvn sonar:sonar. There’s a dependency on org.codehaus.sonar:sonar-plugin-api, here I don’t see who could need this.
And you don’t need the jacoco-maven-plugin dependency, only keep your jacoco configuration in <build><plugins><plugin>.

I have the same issue, getting 0% for code coverage. After so many trails also no luck.
could you please help.

below are my logs …

INFO: Sensor SonarCSS Rules [cssfamily] (done) | time=18902ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=11ms
INFO: Sensor SonarJS [javascript] INFO: 1 source files to be analyzed
INFO: Sensor SonarJS [javascript] (done) | time=1209ms INFO: Sensor ESLint-based SonarJS [javascript] INFO: 1/1 source files have been analyzed



INFO: Sensor SurefireSensor [java] (done) | time=3ms
INFO: Sensor JaCoCoSensor [java]
INFO: JaCoCo report not found: ‘target/jacoco.exec’
INFO: JaCoCo report not found: ‘target/jacoco-it.exec’
INFO: JaCoCo UT report not found: ‘target/jacoco-ut.exec’
INFO: Sensor JaCoCoSensor [java] (done) | time=4ms
INFO: Sensor JavaXmlSensor [java]
INFO: 13 source files to be analyzed
INFO: Sensor JavaXmlSensor [java] (done) | time=697ms
INFO: Sensor HTML [web] INFO: 13/13 source files have been analyzed

// do we need to set any path etc other than adding dependencies in pom.xml?

Hi @Ravi1,

What does it means I have the same issue?
Do you have the same version of SonarQube? Which version do you have?
Do you have the same maven configuration? Do you have the JaCoCo XML report generated?
Did you follow this documentation: [Coverage & Test Data] Importing JaCoCo coverage report in XML format ?
Did you run mvn -X sonar:sonar to try to have more information?