Jacoco.xml report is imported but not showing in SQ gui (0% code coverage)

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarScanner 4.8.0.2856
    SonarQube server 9.9.1.69595
    jacoco 0.8.10

  • what are you trying to achieve
    i run ‘maven clean verify’ and report task.
    i want to see the code coverage in sonarqube results, produce the xml and see the output in the SQ gui

  • what have you tried so far to achieve this
    i have set the property :
    sonar.coverage.jacoco.xmlReportPaths=**/target/site/jacoco/jacoco.xml
    and during the sonarqube scanner phase this is seen in the log:
    INFO: Sensor JaCoCo XML Report Importer [jacoco]
    INFO: Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
    INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=47ms

Also when i go into the project in sonarqube i can see that the jacoco.xml file is found in the correct path (and there are correct values in there) but , still the code coverage is 0%
How can i make it so that the code coverage is shown in the GUI?

Hi,

Welcome to the community!

Could you provide your analysis 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,
i see that you would have to run mvn sonar:sonar -X
But i dont use that way, i use in my module’s pom.xml:

<plugin>
				<groupId>org.jacoco</groupId>
				<artifactId>jacoco-maven-plugin</artifactId>
				<version>${jacoco.version}</version>
				<executions>
				<execution>
					<id>default-report</id>
					<goals>
						<goal>report-aggregate</goal>
					</goals>
					<configuration>
						<formats>
							<format>XML</format>
						</formats>
					</configuration>
					<phase>verify</phase>
				</execution>
				</executions>
			</plugin>

And i run Sonarqube through Azure DevOps with the following yaml:

  - task: Maven@3
              displayName: 'Run Maven Test'
              inputs:
                mavenPomFile: 'pom.xml'
                goals: 'clean verify'
                options: '-P$(APPNAME)'
                publishJUnitResults: false
                javaHomeOption: 'Path'
                jdkDirectory: 'F:\Tools\Java\openjdk-17.0.7'
                mavenVersionOption: 'Default'
                mavenAuthenticateFeed: false
                effectivePomSkip: false
                sonarQubeRunAnalysis: false
            - task: SonarQubePrepare@5
              displayName: 'Prepare SonarQube Analysis'
              inputs:
                SonarQube: 'Sonar-P'
                scannerMode: 'CLI'
                configMode: 'manual'
                cliprojectKey: $(APPNAME)-API
                cliprojectName: '$(APPNAME)-API'
                cliSources: '.'
                extraProperties: |
                  sonar.exclusions=**/*.java
                  sonar.coverage.jacoco.xmlReportPaths=**/target/site/jacoco-aggregate/jacoco.xml
                  sonar.java.coveragePlugin=jacoco
            - task: SonarQubeAnalyze@5
              displayName: 'Run SonarQube Code Analysis'
              env:
                JAVA_HOME: 'F:\Tools\Java\openjdk-17.0.7'

Hi,

Ordinary analysis logs should be generated automatically, without the need for -X on the Maven command line. Although if you did want debug-level logging, you could easily add to your extraProperties:

sonar.log.level=DEBUG
or
sonar.verbose=true

 
HTH,
Ann

Hi,

Post it here, redacted as necessary.

 
Ann

Hi,

From what I can see - and as you said from the start - your report is imported without errors:

2023-06-19T13:01:30.7573636Z 15:01:30.754 INFO: Sensor JaCoCo XML Report Importer [jacoco]
2023-06-19T13:01:30.7807228Z 15:01:30.770 INFO: Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
2023-06-19T13:01:30.7807627Z 15:01:30.770 DEBUG: Reading report 'F:\Agents\4\ws\118\s\jaf-guilogs\target\site\jacoco-aggregate\jacoco.xml'
2023-06-19T13:01:30.8172745Z 15:01:30.801 INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=47ms

Typically in a case where the report is read by the coverage that shows up in SonarQube is below expectations, there are errors reported during the coverage report import. That’s not the case here, so you should take a look at what’s in your report:

  • does it include all the files you think it should?
  • does it show the coverage you expect for those files?

 
Ann

Hi, there is correct data in the .xml file as far as i can see.
but it seems it just isnt showed in the gui for the project… as it should have more than 0% coverage… im guessing there should be some other configuration in sonarqube to see that? should i change something in the general settings?

Hi,

Going back to your log…

We’re dealing with a JaCoCo report? So it covers Java files?

Because I’m seeing this in your log:

2023-06-19T13:01:25.4664921Z 15:01:25.462 INFO: Indexing files...
2023-06-19T13:01:25.4665364Z 15:01:25.462 INFO: Project configuration:
2023-06-19T13:01:25.4673535Z 15:01:25.462 INFO:   Excluded sources: src/test/**/*, **/*.java

Exactly how many files, and of what language(s) show up in SonarQube for you?

 
Ann

I see actually that sonarqube says/thinks its XML and not java…
1.2K lines XML so that might be the issue? how to make it see that it is java code instead of xml ?

Hi,

If you look at those files, are the contents Java or XML?

Also, take a look at your exclusion settings, and edit them so you’re not excluding **/*.java.

 
Ann

Yes i understand now, i excluded the java files, now its working without that.

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