Blackbox testing jacoco xml report imports to Sonarqube?

I just got one standalone jacoco.xml coverage report file from a blackbox testing, it is java-based old project, there is no unit testing applied, no maven attached. It is built and tested by javac, jar, .exe cases. I tried to import it to sonarqube but failed all the time. I want to know what is the minimum configuration or information(source, lib…, sonarqube options) which can help me to do that good or am I totally wrong?

Must-share information (formatted with Markdown):
*** which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)**

17:20:26.886 INFO: Scanner configuration file: D:\sonar-scanner-4.3.0.2102-windows\bin..\conf\sonar-scanner.properties
17:20:26.888 INFO: Project root configuration file: NONE
17:20:26.912 INFO: SonarScanner 4.3.0.2102
17:20:26.912 INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
17:20:26.912 INFO: Windows 10 10.0 amd64

17:20:29.215 DEBUG: Plugins:
17:20:29.216 DEBUG: * SonarPython 2.8.0.6204 (python)
17:20:29.216 DEBUG: * SonarCSS 1.2.0.1325 (cssfamily)
17:20:29.216 DEBUG: * JaCoCo 1.1.0.898 (jacoco)
17:20:29.217 DEBUG: * SonarGo 1.6.0.719 (go)
17:20:29.217 DEBUG: * SonarKotlin 1.5.0.315 (kotlin)
17:20:29.217 DEBUG: * Svn 1.9.0.1295 (scmsvn)
17:20:29.217 DEBUG: * SonarJS 6.2.0.12043 (javascript)
17:20:29.217 DEBUG: * SonarRuby 1.5.0.315 (ruby)
17:20:29.217 DEBUG: * SonarScala 1.5.0.315 (sonarscala)
17:20:29.217 DEBUG: * C# Code Quality and Security 8.6.1.17183 (csharp)
17:20:29.217 DEBUG: * Java Code Quality and Security 6.3.0.21585 (java)
17:20:29.217 DEBUG: * SonarHTML 3.2.0.2082 (web)
17:20:29.217 DEBUG: * Git 1.11.1.2008 (scmgit)
17:20:29.218 DEBUG: * SonarFlex 2.5.1.1831 (flex)
17:20:29.218 DEBUG: * SonarXML 2.0.1.2020 (xml)
17:20:29.218 DEBUG: * SonarPHP 3.3.0.5166 (php)
17:20:29.218 DEBUG: * SonarTS 2.1.0.4359 (typescript)

*** what are you trying to achieve**
wanna import only jacoco xml-format coverage report to Sonarqube.

*** what have you tried so far to achieve this**
Run the following cmd from sonar-scanner,

C:\sonar-scanner-4.3.0.2102-windows\bin\sonar-scanner -X -Dsonar.projectKey=engine-javaupoc-jacoco -Dsonar.coverage.jacoco.xmlReportPaths=jacoco.xml

While I always get the issue like the following, and ) is reported in Sonarqube project.

:
17:20:33.228 INFO: Sensor JaCoCo XML Report Importer [jacoco]
17:20:33.230 INFO: Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
17:20:33.230 DEBUG: Reading report ‘D:\jacoco-rest\jacoco-xrpt\javaupoc-jacoco.xml’
17:20:33.298 INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=71ms
17:20:33.298 INFO: Sensor JavaXmlSensor [java]
17:20:33.302 INFO: 1 source files to be analyzed
17:20:33.451 INFO: Load project repositories
17:20:33.460 DEBUG: GET 404 http://localhost:9000/batch/project.protobuf?key=engine-javaupoc-jacoco2 | time=9ms
17:20:33.460 DEBUG: Project repository not available - continuing without it
17:20:33.461 INFO: Load project repositories (done) | time=10ms
17:20:33.461 DEBUG: ‘javaupoc-jacoco.xml’ generated metadata with charset ‘UTF-8’
17:20:34.240 INFO: 1/1 source files have been analyzed
17:20:34.240 INFO: Sensor JavaXmlSensor [java] (done) | time=942ms
17:20:34.240 INFO: Sensor HTML [web]
17:20:34.244 INFO: Sensor HTML [web] (done) | time=4ms
17:20:34.244 INFO: Sensor XML Sensor [xml]
17:20:34.246 INFO: 1 source files to be analyzed
17:20:34.692 DEBUG: Count lines in file:///D:/jacoco-rest/jacoco-xrpt/javaupoc-jacoco.xml
17:20:35.021 INFO: Sensor XML Sensor [xml] (done) | time=777ms
17:20:35.022 INFO: 1/1 source files have been analyzed
17:20:35.025 INFO: ------------- Run sensors on project
17:20:35.027 DEBUG: ‘Generic Coverage Report’ skipped because one of the required properties is missing
17:20:35.027 DEBUG: ‘Java CPD Block Indexer’ skipped because there is no related file in current project
17:20:35.028 DEBUG: Sensors : Zero Coverage Sensor
17:20:35.028 INFO: Sensor Zero Coverage Sensor
17:20:35.029 INFO: Sensor Zero Coverage Sensor (done) | time=1ms
17:20:35.031 INFO: SCM Publisher No SCM system was detected. You can use the ‘sonar.scm.provider’ property to explicitly specify it.
17:20:35.032 INFO: CPD Executor Calculating CPD for 0 files
17:20:35.034 INFO: CPD Executor CPD calculation finished (done) | time=0ms
17:20:35.141 INFO: Analysis report generated in 106ms, dir size=1 MB
17:20:35.302 INFO: Analysis report compressed in 161ms, zip size=320 KB
17:20:35.302 INFO: Analysis report generated in D:\jacoco-rest\jacoco-xrpt.scannerwork\scanner-report
17:20:35.302 DEBUG: Upload report
:

Hi,

Welcome to the community!

Nothing in your analysis log snippet jumps out at me as a problem…

In terms of minimum configuration to analyze this project, the docs on Java-specific analysis will help.

As indicated in the main parameters list you’ll need to provide

  • sonar.host.url
  • sonar.projectKey

And mandatory to analyze Java:

  • sonar.java.binaries the path to your compiled class files

Good but optional

  • sonar.sources - this defaults to . so it’s optional, but better to provide a targeted path.

And then to get your coverage file imported, there’s

  • sonar.coverage.jacoco.xmlReportPaths

but you seem to already know this one. :smiley:

 
HTH,
Ann

Thanks for reply,

I run the sonar-scanner cmd like,

sonar-scanner -X -Dsonar.projectKey=engine-javaupoc-jacoco ^
-Dsonar.host.url=http://localhost:9000 ^
-Dsonar.coverage.jacoco.xmlReportPaths=javaupoc-jacoco.xml ^
-Dsonar.java.binaries=D:\win\build\java

while still get 0 reported from sonar server, and log showed something below,
It looked XML jacoco report is read, while nothing is analyzed, and then issue is shown in debug line. I did not see such a line in my other maven jacoco project. Is it problem?

11:23:35.699 DEBUG: ‘Generic Coverage Report’ skipped because one of the required properties is missing
11:23:35.700 DEBUG: ‘Java CPD Block Indexer’ skipped because there is no related file in current project

11:23:34.098 INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=56ms
11:23:34.101 INFO: Sensor JavaXmlSensor [java]
11:23:34.106 INFO: 1 source files to be analyzed
11:23:34.192 INFO: Load project repositories
11:23:34.200 DEBUG: GET 404 http://localhost:9000/batch/project.protobuf?key=engine-javaupoc-jacoco | time=8ms
11:23:34.203 DEBUG: Project repository not available - continuing without it
11:23:34.204 INFO: Load project repositories (done) | time=12ms
11:23:34.204 DEBUG: ‘javaupoc-jacoco.xml’ generated metadata with charset ‘UTF-8’
11:23:34.926 INFO: Sensor JavaXmlSensor [java] (done) | time=825ms
11:23:34.928 INFO: 1/1 source files have been analyzed
11:23:34.928 INFO: Sensor HTML [web]
11:23:34.933 INFO: Sensor HTML [web] (done) | time=5ms
11:23:34.933 INFO: Sensor XML Sensor [xml]
11:23:34.935 INFO: 1 source files to be analyzed
11:23:35.400 DEBUG: Count lines in file:///D:/jacoco-rest/jacoco-xrpt/javaupoc-jacoco.xml
11:23:35.689 INFO: Sensor XML Sensor [xml] (done) | time=756ms
11:23:35.689 INFO: 1/1 source files have been analyzed
11:23:35.694 INFO: ------------- Run sensors on project
11:23:35.699 DEBUG: ‘Generic Coverage Report’ skipped because one of the required properties is missing
11:23:35.700 DEBUG: ‘Java CPD Block Indexer’ skipped because there is no related file in current project
11:23:35.701 DEBUG: Sensors : Zero Coverage Sensor
11:23:35.701 INFO: Sensor Zero Coverage Sensor

By the way, it looks like sonar-scanner does not tell the project is java-based, right? Could you please let me know how I can do more debugging on this?

Hi,

This line:

indicates that analysis isn’t finding any Java files. It sounds like you need to review the value of sonar.sources.

One good way to do that might be to use sonar.scanner.dumpToFile=[file name] to see the values being used during analysis.

 
Ann

I will try dump. Thanks, @ganncamp.

@ganncamp, I got it fixed by correctly pointing to the source code location. Thanks really.

It seemed I must keep the source code in the same directory where my jacoco.xml is saved. The -Dsonar-source=(the other place where the same source is saved) is not respected?
Tao

Hi,

Your report doesn’t need to be in the source directory. Just point to it correctly. Also, the paths in the report need to match paths to the code at analysis time. I.E. you can’t run the report on one file system and then feed it into analysis on the other because the paths likely won’t match.

 
HTH,
Ann

Hi,

I am trying to do the same thing of creating a coverage report from blackbox testing. I was wondering how you set up JaCoCo to capture the coverage data. Thanks.