Unable to view complete code coverage on Sonar Cloud server when used multi module Gradle project

We are using multi module gradle project and need to see the code coverage on sonar cloud
we have done below configuration in build.gradle of each subproject

plugins {
    id "jacoco"
    id "org.sonarqube" version '3.0'
}

jacocoTestReport {
    reports {
        xml.enabled true
    }
}

and 
  tasks["test"].finalizedBy 'jacocoTestReport'

We have also tried with
jacoco-report-aggregation plugin and its configuration

With this configuration we are not able to view complete code coverage on sonar cloud

Kindly let us know your inputs, any way to make sonar work for Multi Module Projects.

We are able to see the code coverage in local report. But when we try to push the report in sonarcloud.io most of the is uncovered by Jacoco+Junit test cases.

Hi,

Welcome to the community!

Are you passing the coverage reports in to analysis?

 
Ann

Hi Ann,

Yes we are passing coverage reports in analysis.

Please revert if any other information require

Thanks in advance

Vishal

Hi Vishal,

Could you share your anlaysis log?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Ann

Hi Ann,

Please find attached sonar analysis report. Please check whether this will be useful to you?

Sonar_Analysis_Report.txt (90.6 KB)

Thanks,
Vishal

Hi Vishal,

What you’ve shared appears to be the SonarScanner Context. I need the analysis log - the output from the analysis command.

 
Ann

Hi Vishal,

Thanks for the log. Unfortunately, your Gradle analysis command didn’t include the --debug flag, so there’s almost no logging relevant to analysis.

Can you add the --debug flag and provide a new log, please?

Oh, and you’ve exposed your authentication token. You should revoke it immediately, create a new one and redact it from the next log you send. :smiley:

 
Thx,
Ann

Hi G Ann Campbell,

This is Uday colleague of Vishal.I want to help you with gradle debug log. I am sharing you the debug log.

gradle-sonar-debug-log.txt.zip (5.3 MB)

Let me know if you need anything else apart from this.

Hi,

From the log you provided, it looks like the coverage report is read for most modules. There’s one where no file was found.

2023-04-18T11:12:27.059+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Sensor JaCoCo XML Report Importer [jacoco]
2023-04-18T11:12:27.063+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
2023-04-18T11:12:27.063+0000 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Reading report '/workspace/credit-services/build/reports/jacoco/test/jacocoTestReport.xml'
2023-04-18T11:12:27.083+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=25ms
...
2023-04-18T11:12:27.375+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Sensor JaCoCo XML Report Importer [jacoco]
2023-04-18T11:12:27.375+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
2023-04-18T11:12:27.376+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] No report imported, no coverage information will be imported by JaCoCo XML Report Importer
2023-04-18T11:12:27.376+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=1ms
...
2023-04-18T11:12:28.913+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Sensor JaCoCo XML Report Importer [jacoco]
2023-04-18T11:12:28.913+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
2023-04-18T11:12:28.913+0000 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Reading report '/workspace/recon-transaction-report-services/build/reports/jacoco/test/jacocoTestReport.xml'
2023-04-18T11:12:28.922+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=10ms
...
2023-04-18T11:12:33.018+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Sensor JaCoCo XML Report Importer [jacoco]
2023-04-18T11:12:33.019+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
2023-04-18T11:12:33.019+0000 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Reading report '/workspace/transaction-history-details-lib/build/reports/jacoco/test/jacocoTestReport.xml'
2023-04-18T11:12:33.055+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=37ms
...
2023-04-18T11:12:35.205+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Sensor JaCoCo XML Report Importer [jacoco]
2023-04-18T11:12:35.205+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
2023-04-18T11:12:35.205+0000 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Reading report '/workspace/network-message-lib/build/reports/jacoco/test/jacocoTestReport.xml'
2023-04-18T11:12:35.216+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=12ms
...

Can you be more precise about what’s going wrong / what’s missing?

 
Ann

HI Ann,

let me explain you the scenario.
We have gradle multi module project where we have services in one module and its corresponding DTOs and entities are in other module, We have written Junits for services, So the issue is when we run code coverage task on Sonar Cloud it will only show the coverage for services and not showing coverage for DTOs and entities which are used in these services.
As mentioned in problem statement, We are able to see the code coverage in local report. But when we try to push the report in sonarcloud.io coverage is not shown in cloud

For example,
As you can see in the provided logs ,
We have module Credit-Services which include Services
and its corresponding DTOs and Entities are in another module named Engine-Lib,
when we ran code coverage report on sonar cloud we are able to see code coverage of Credit-Services but unable to see coverage of its corresponding DTOs and Entities

Thanks,
Vishal

Hi Vishal,

In what coverage report are the DTOs and Entities included? And with what file paths? The coverage reports need to have file paths that make sense from an analysis perspective.

 
Ann

HI Ann,

Could you please elaborate your question? Also, which file paths you are mentioning could you please give some example?


Above is snap of DTOs which are not covered in code coverage even if we consume them in services

Hi,

From you log it appears that you have multiple coverage reports, not just one. I’m asking whether coverage of the DTOs is included in the report for the DTO module or in some other report. And if the latter, what do the file paths in the report look like for the DTOs?

 
Ann

Hi Ann,
Yes we have multiple coverage reports. Coverage of DTOs are included in the report for the DTO module and Coverage of Services are included in the report for the Service module
DTOs coverage report path –

2023-04-18T11:12:39.331+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Sensor JaCoCo XML Report Importer [jacoco]
2023-04-18T11:12:39.332+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
2023-04-18T11:12:39.332+0000 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Reading report '/workspace/common-lib/build/reports/jacoco/test/jacocoTestReport.xml'
2023-04-18T11:12:39.337+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=6ms

Service Coverage Report Path –

2023-04-18T11:12:27.059+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Sensor JaCoCo XML Report Importer [jacoco]
2023-04-18T11:12:27.063+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
2023-04-18T11:12:27.063+0000 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Reading report '/workspace/credit-services/build/reports/jacoco/test/jacocoTestReport.xml'
2023-04-18T11:12:27.083+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=25ms

and

2023-04-18T11:12:46.269+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Sensor JaCoCo XML Report Importer [jacoco]
2023-04-18T11:12:46.270+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
2023-04-18T11:12:46.270+0000 [DEBUG] [org.sonarqube.gradle.SonarQubeTask] Reading report '/workspace/engine-lib/build/reports/jacoco/test/jacocoTestReport.xml'
2023-04-18T11:12:46.299+0000 [INFO] [org.sonarqube.gradle.SonarQubeTask] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=30ms

These are the report paths which are there in below attachment

gradle-sonar-debug-log.txt.zip (5.3 MB)

Hi,

Cool. Now when you open those reports up in a text editor, what do the paths in them look like? Do they match the filepaths that SonarQube shows you when you browse the project’s Code tab? E.G.

 
Ann

Hi Ann,

I am unable to open those reports up in a text editor. Can you please guide on how i can open those reports as these reports are in Sonar cloud server and not on local?

Any help regarding this will be appreciated

Thanks,
Vishal

Hi Vishal,

What format reports are you providing to analysis? It should be XML.

 
Ann

HI Ann,

We are providing xml format only to analysis

jacocoTestReport {
reports {
xml.enabled true
csv.enabled false
html.enabled false
}
}

Could you please confirm, where we can see this format on Sonar cloud server?

Thanks,
Vishal

Hi Vishal,

Given this:

I don’t understand this:

 
Ann