sonar.coverage.jacoco.xmlReportPaths not showing code coverage but the deprecated sonar.jacoco.reportPaths shows code coverage

Bug Statement:
I am using sonar.jacoco.reportPaths for reporting code coverage on SonarQube. But when I use the same with sonar.coverage.jacoco.xmlReportPaths then, it is now showing code coverage on Sonarqube server. As the previous property is deprecated, I need to move on new one. But with that code coverage is not working.

Below are the plugins and version used to report the code coverage.
SonarQube version is Version 7.9.1
Android Sonar plugin is org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1
Jococo android plugin is com.dicedmelon.gradle:jacoco-android:0.1.4
Jococo toolchain tool version is 0.8.3

Below are the property used

        sonarqube {
        properties {
            // Root project information
            property 'sonar.projectKey', 'AppNameAndroid'
            property 'sonar.projectName', 'AppName-Android'
            // Some properties that will be inherited by the modules
            property 'sonar.sources', 'src/main/java/com/app_name/app'
            property 'sonar.sourceEncoding', 'UTF-8'
            property 'sonar.exclusions', '**/*.html,**/*.css,**/*.png,**/*.jpg,**/*.JPG,**/io/ionic*,**/io/ionic**,**/io/ionic**/*.java,**/org/*,**/org/**,**/org/**/*.java,**/cordova/*,**/cordova/**,**/cordova/**/*.java,**/android/*,**/android/**,**/android/**/*.java,**/apache/commons/**'
            property 'sonar.scm.provider', 'git'
            property 'sonar.java.source', '1.8'
            property 'sonar.tests', ["src/test/java"]
            property 'sonar.java.coveragePlugin', "jacoco"
            property 'sonar.coverage.exclusions', '**/*.html,**/*.css,**/*.png,**/*.jpg,**/*.JPG,**/io/ionic*,**/io/ionic**,**/io/ionic**/*.java,**/org/*,**/org/**,**/org/**/*.java,**/cordova/*,**/cordova/**,**/cordova/**/*.java,**/android/*,**/android/**,**/android/**/*.java,**/apache/commons/**'
            // Below property needs to be use very soon
            //property 'sonar.coverage.jacoco.xmlReportPaths', "build/reports/jococo/jococoTestDevReleaseUnitTestReport/jacocoTestDevReleaseUnitTestReport.xml"
            property 'sonar.jacoco.reportPaths', "${project.buildDir}/jacoco/testDevReleaseUnitTest.exec"
            property 'sonar.junit.reportsPath', "${project.buildDir}/test-results/testDevReleaseUnitTest"

            property 'sonar.java.binaries', "${project.buildDir}/intermediates/javac/devRelease/compileDevReleaseJavaWithJavac/classes/com/visualogyx"
            property 'sonar.projectVersion', getFlavorVersionCode()

        }
    }

#bug: jococo xml report
#bug: jococo code-coverage issue

@Shreyash, do you create XML report during the build? Please have a look at the guide here how to do it [Coverage & Test Data] Importing JaCoCo coverage report in XML format

HI,
Thanks for your reply. Yes, I have created XML report and also assign that to the new sonar properly. Right now, it is commented on above post as If I uncomment it and upload the analysis then it is not showing code coverage.

Please help towards that. Thanks.

@saberduck
This is what I got when I use sonar.jacoco.reportPaths

image

Thanks.

This is what I got when I use sonar.coverage.jacoco.xmlReportPaths

image

I hope you got my point. Do let me know if you need any information for same.

You have to make sure that the data you are importing actually contain any coverage, I don’t think that the issue is in SonarQube, but that the report itself is not correct.

Try to create html report in addition to the XML one, and see if the numbers inside the report are correct.

@saberduck

I have done the same thing. But got same results as below in both the condition.

From the screenshot I see that total coverage is 0%, SonarQube is only going to display what’s in the report. You would need to fix your report to have the same numbers as before.

Try to pinpoint where the difference happens (which file/module) and troubleshoot why the coverage is missing in that particular locations.

@saberduck
Ok. But my pin point is, why code coverage report get changed with the single property, if I upload it to SonarQube. While the same report raised in local machine.

There is something get changed with that sonar property. I need proper guidance if I am defining it wrong.

Please update me for same.

Thanks.

@saberduck

Is there any luck to get the issue and provide a guideline to resolve it?
It would be great if you can check and update for the same.

Thanks.

hello,

you need to investigate and fix the XML report. The problem is not in SonarQube, SonarQube is only showing the data you are providing in the XML report.

@saberduck

I have raised the issue on Jacoco plugin repository for same. They are saying that the issue is from sonarQube, But not from thier end. Now, what should be consider here.

I feel like, the issue is from sonarQube only. Otherwise, how it get changed by changing deprecated flag and using new one.
Please review this and help to resolved it.

Looking to have more details in resolving this issue.
Thanks.

@saberduck

Hi, If you check the details given at below link, I found that the issue is from either configuration or from the SonarQube. Can you please check for same and help me for that.

Thanks.

@Shreyash, the issue is most likely in the configuration of your build. To fix it, it would require that you investigate how your build is creating coverage report and to understand where the difference arises.

Also, this is not just simple property change, to achieve the same results, you have to modify your build to compute the right data.

In this screenshot,
image

can you investigate, which lines are covered (which source files, which module) and how the coverage is obtained (where are the tests that provide that coverage, how are they launched)?

How do you create XML report? Can you share relevant configuration from your build?

1 Like

OK Thanks.

I will look into it and will update you. FYI, I got an update from Jacoco plugin that I was using third party plugin for that, So I will probably change it and then will try it.

Thanks for your support. I will reach to you in case your attention is required in that.

Thanks.

@saberduck

I have used the valid library as mentioned in this thread for the Android Gradle plugin. I do have a reports in XML & HTML. Both show valid coverage. Please review below images for the same.

Overall coverage

Now, Observe the same result for one of the class AuthBody.java
AuthBody result in HTML report

AuthBody result in XML report

As per above observation, I found that the XML report is generated properly but somehow, it is not getting reflacted on SonarQube server.

I have configured the below properties for the same.

sonarqube {
properties {
// Root project information
property ‘sonar.projectKey’, ‘ProjectNameAndroid’
property ‘sonar.projectName’, ‘ProjectName-Android’

    // Some properties that will be inherited by the modules
    property 'sonar.sources', 'src/main/java/com/visualogyx/app'
    property 'sonar.sourceEncoding', 'UTF-8'
    property 'sonar.exclusions', '**/*.html,**/*.css,**/*.png,**/*.jpg,**/*.JPG,**/io/ionic*,**/io/ionic**,**/io/ionic**/*.class,**/org/*,**/org/**,**/org/**/*.class,**/cordova/*,**/cordova/**,**/cordova/**/*.class,**/android/*,**/android/**,**/android/**/*.class,**/apache/commons/**,**/io/realm/**,**/com/mikhaellopez/**,**/io/michaelrocks/**,**/io/michaelrocks/**,**/org/apache/**,**/databinding/**/*.*,**/android/databinding/*Binding.*,**/BR.*,**/R.*,**/R$*.*,**/BuildConfig.*,**/Manifest*.*,**/*_MembersInjector.*,**/Dagger*Component.*,**/Dagger*Component$Builder.*,**/*Module_*Factory.*,**/*Activity*.*,**/*Adapter*.*,**/*ViewPager*.*,**/*ViewHolder*.*,**/*Module*.*'
    property 'sonar.scm.provider', 'git'
    property 'sonar.java.source', '1.8'
    property 'sonar.tests', ["src/test/java"]
    property 'sonar.java.coveragePlugin', "jacoco"
    property 'sonar.coverage.exclusions', '**/*.html,**/*.css,**/*.png,**/*.jpg,**/*.JPG,**/io/ionic*,**/io/ionic**,**/io/ionic**/*.class,**/org/*,**/org/**,**/org/**/*.class,**/cordova/*,**/cordova/**,**/cordova/**/*.class,**/android/*,**/android/**,**/android/**/*.class,**/apache/commons/**,**/io/realm/**,**/com/mikhaellopez/**,**/io/michaelrocks/**,**/io/michaelrocks/**,**/org/apache/**,**/databinding/**/*.*,**/android/databinding/*Binding.*,**/BR.*,**/R.*,**/R$*.*,**/BuildConfig.*,**/Manifest*.*,**/*_MembersInjector.*,**/Dagger*Component.*,**/Dagger*Component$Builder.*,**/*Module_*Factory.*,**/*Activity*.*,**/*Adapter*.*,**/*ViewPager*.*,**/*ViewHolder*.*,**/*Module*.*'
    // Below property needs to be use very soon
    property 'sonar.coverage.jacoco.xmlReportPaths', "build/reports/jococo/jococoTestReport/jacocoTestReport.xml"
    //property 'sonar.jacoco.reportPaths', "${project.buildDir}/jacoco/testDevReleaseUnitTest.exec"
    property 'sonar.junit.reportsPath', "${project.buildDir}/test-results/testDevReleaseUnitTest"
    property 'sonar.java.test.binaries', "${project.buildDir}/reports/tests/testDevReleaseUnitTest/classes"
    property 'sonar.java.binaries', "${project.buildDir}/intermediates/javac/devRelease/compileDevReleaseJavaWithJavac/classes/com/visualogyx/app"
    property 'sonar.projectVersion', getFlavorVersionCode()

}

}

subprojects {
sonarqube {
skipProject = true
}
}

After configuring this results with sonar properties, I have 0% coverage on SonarQube Server.

image

Even the same class (AuthBody.java) shows 0 lines covered on SonarQube server.

Now, Either I do mistake in providing details or the SonarQube server is not detecting the report correctly so that it can be reflacted.

Can you please look at this now. Please do let me know If is there any issue from my side to provide the details.

Thanks.

1 Like

I’ve just noticed, that value for the property has strange path

 property 'sonar.coverage.jacoco.xmlReportPaths', "build/reports/jococo/jococoTestReport/jacocoTestReport.xml"

You have jococo instead of jacoco in the path two times. Can you try if this is the reason why the report is not picked up?

@saberduck

Yes, you catch it right. That was one of the issues. But even after that, If I do analysis and upload it to sonarqube it shows 0.0% coverage. I am trying the same again. But seems like the issue is not resolved yet even after that change.

The change is as below:

property 'sonar.coverage.jacoco.xmlReportPaths', 'build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml'

Thanks.

Are you changing this path somehow? Because default path is build/reports/jacoco/test/jacocoTestReport.xml

Can you post debug logs from the analysis?

This is how, I have the structure defined.

Thanks.