SonarQube community version 8.3 is showing 0% code coverage, however with the same configurations I am able to get coverage in community version 8.1

SonarQube version : sonarqube-8.3.1.34397 and sonarqube-8.1.0.31237
SonarScanner version : sonar-scanner-4.3.0.2102
Jacoco version in java : 0.8.3
Plugin in Java : jacoco-maven-plugin and no plugins added in javascript(yet was working for 8.1 version)
java version 12 and npm version 6.13.4

For java property file :

sonar.projectKey=com.pluang:GoldTransactionService
sonar.projectName=GoldTransactionService
sonar.projectVersion=1.0.0
sonar.sources=src/main
sonar.sourceEncoding=UTF-8
sonar.language=java
sonar.java.binaries=target/classes
sonar.test.inclusions=src/test
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

For java script i am using this :

sonar.projectKey=pluang-product-api
sonar.projectName=Pluang Product API
sonar.projectVersion=1.0
sonar.language=js
sonar.sources=services
sonar.sourceEncoding=UTF-8
sonar.exclusions=src/**/*.spec.js
sonar.test.inclusions=src/**/*.spec.js
sonar.coverage.exclusions=src/**/*.spec.js,src/**/*.mock.js,node_modules/*,coverage/lcov-report/*
sonar.javascript.lcov.reportPaths=coverage/lcov.info

Even now with these exact same configurations i am getting coverage report for both the projects in version 8.1 bit not in 8.3. I have checked my coverage reports are getting generated correctly as well each time. Its just sonar is not picking that coverage file. Please help here. I have read lots of articles and discussions around the same version issues but didn’t find anything concrete or helpful.

Just a heads up for NodeJs project specifically, its working in even 8.3 version project when i download directly but when i download the docker image and run sonarqube through that, it doesn’t work again.
Anticipating a quick response, as i have been looking for sometime now to this issue, but no luck. Thanks in advance.

1 Like

Hi,

From 8.2 SonarQube no longer reads the .exec format. Along with that, the sonar.jacoco.reportPath parameter is now ignored. Reading the .exec format had been deprecated for a while. It’s replaced by reading the .xml format, as fed from the new-ish sonar.coverage.jacoco.xmlReportPaths parameter.

 
HTH,
Ann

 

P.S. To be fair, this change got left out of the Upgrade Notes, an oversight we’ll correct.

Hi Ann,

Thanks for the reply. I saw these discussion but i was not able to deduce the exact to be done.

As per this https://docs.sonarqube.org/display/PLUG/JaCoCo+Plugin, its saying this sonar-jacoco plugin is enabled by default since SonarQube 7.4+ and it should show the reports in xml format. So, what all i need to change now, as i guess it should not be a more tedious task than earlier.
My current build plugin is like this :

<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <configuration>
                    <destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
                    <dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
                    <output>file</output>
                    <append>true</append>
                    <excludes>
                        <exclude>*MethodAccess</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <id>jacoco-initialize</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <phase>test-compile</phase>
                    </execution>
                    <execution>
                        <id>jacoco-site</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

And as per this https://community.sonarsource.com/t/coverage-test-data-importing-jacoco-coverage-report-in-xml-format/12151, i should see the jacoco.xml file but this is not getting generated. It’s just i have one extra configuration tab here in my pom file. Can you please help me how i should change my pom.xml accordingly, as i saw there has been mention in few of the forum discussions of some specific formats we have to give which will enable jacoco to read this xml file.

Thanks in Advance,
Kunal

Hi,

I’m neither a Mavenista nor a JaCoCo expert. I can’t tell you how to change your pom to generate the XML report. I can tell you how to update your analysis parameters to read the report you’ll configure JaCoCo to generate: this is where the sonar.coverage.jacoco.xmlReportPaths parameter comes in.

And you’ve probably already picked up on this, but just to make it super clear for posterity: SonarQube analysis does not run your tests or generate the coverage report. It only reads the report - if you tell it to.

 
HTH,
Ann

Cool, No problem @ganncamp, i will get this working. To your second part of the reply, yes that i am aware of and doing it with surefire and jacoco, which generates coverage reports of the run tests :slight_smile:

Just one more thing if you can help, can you please let me know of any other change like the one you mentioned in the new versions after 8.1, specifically for Javascript projects in regard to the visualisation of the coverage reports on SonarQube. I had already shared the properties file of my javascript project in the description of my question above.

Regards,
Kunal

Hi Kunal,

I’m not aware of anything related to JavaScript.

 
Ann

I was able to get coverage in the updated versions of sonar, hence posting as it might help others to fix this issue, below are the changes in pom.xml.

<!--Sonar properties -->
        <jacoco.version>0.8.3</jacoco.version>
        <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        **<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>**
        <sonar.language>java</sonar.language>

By default SonarQubeUI takes this path : ${project.basedir}/target/site/jacoco/jacoco.xml so sticking to that. It will change in case of aggregated reports.

<plugin>
                <groupId>org.sonarsource.scanner.maven</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>3.7.0.1746</version>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <executions>
                    <execution>
                        <id>prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        **<phase>test-compile</phase>**
                    </execution>
                    <execution>
                        <id>report</id>
                        **<phase>package</phase>**
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>

Please see the maven phase is important in the execution for the reports - made it bold (check your jenkins pipeline and java code both for the phase).
Others project specific parameters like projectKey, projectVersion, name and others in my properties file. I was also able to get it done in the NodeJs project. Feel free to reach out to me in case you face any issues.

1 Like

hello @Kunal_Singh,

please post your issue (if there is any) with JavaScript project as separate topic, as different people will look into it to help if needed.

Hi @saberduck,
There was no issue as such because of the version mismatch. It was my configuration on Jenkins and the coverage folder i used, was creating issues.

For others who are looking for java script project configuration for sonar, the property file that i posted at first in my problem worked. And to mention, I used Jest for coverage.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.