Trying to import aggregated jacoco file into sonar for code coverage

jacoco
java
coverage

(Mikael Petterson) #1

SonarQube, 6.7.5.38563
Code Analyzer for Java * 5.7 (build 15470) installed

I am trying to import the jacoco aggregated-report for my maven multi-module project into sonar.

I tried:

mvn -B clean org.jacoco:jacoco-maven-plugin:0.8.2:prepare-agent install

and then:

mvn sonar:sonar -P sonar4

I can see that the aggregate-report is executed in first step.

— jacoco-maven-plugin:0.8.2:report-aggregate (report-aggregate) @ coverage —
[INFO] Loading execution data file /repo/eraonel/git/helpers/target/jacoco.exec
[INFO] Loading execution data file /repo/eraonel/git/manager/target/jacoco.exec
[INFO] Loading execution data file /repo/eraonel/git/2temp/target/jacoco.exec
[INFO] Analyzed bundle ‘helpers’ with 2033 classes
[INFO] Analyzed bundle ‘regression-tests’ with 328 classes
[INFO] Analyzed bundle ‘manager’ with 1306 classes
[INFO] Analyzed bundle ‘2temp’ with 129 classes
[INFO] Analyzed bundle ‘actions’ with 5047 classes
[INFO] Analyzed bundle ‘extension’ with 25 classes
[INFO] Analyzed bundle ‘engine’ with 207 classes

I my coverage module I set:

<sonar.jacoco.reportPaths>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPaths>

according to:

https://docs.sonarqube.org/display/PLUG/Code+Coverage+by+Unit+Tests+for+Java+Project

I guess jacoco.exec is a file name and that this is the file that sonar looks for when I run sonar:sonar.

I can see in log something like:

[INFO] Sensor SurefireSensor [java] (done) | time=3346ms
[INFO] Sensor JaCoCoSensor [java]
[INFO] Analysing /repo/eraonel/git/helpers/target/jacoco.exec
[INFO] No information about coverage per test.
[INFO] Sensor JaCoCoSensor [java] (done) | time=2546ms

I check my sonarqube and I cannot see any updates.

However I cannot see:

[INFO] Analysis reports compressed in 421ms, zip size=142 KB
[INFO] Analysis report uploaded in 66ms
[INFO] ANALYSIS SUCCESSFUL, you can browse http:///sonar/dashboard/index

And I double-checked and found that there is no coverage in sonarqube server.

My questions are:

  1. Is this a directory path, ${project.basedir}/target/jacoco.exec and what will sonar look for in here?
  2. What should be the format of the aggregated jacoco file?
  3. Could I get converage in sonarqube without an external coverage file? If yes how?

br,

//mikael


Jacoco.exec for maven multimodule project is not
(Liam) #2

It sounds like your jacoco.exec does not have any coverage data. Either no unit tests run. or the maven surefire plugin has not been passed the jacoco agent (which is the output of jacoco’s prepare-agent)


(Mikael Petterson) #3

Hi,

I checked the separate maven modules and each had a file like:

1192498 Oct 3 12:49 jacoco.exec

Then I checked where I have the resulting one:

cd /repo/eraonel/git/coverage/target/aggregate/jacoco.exec/
index.html                    jacoco-sessions.html          jacoco.xml                    2temp/  extension/         manager/             
jacoco-resources/             jacoco.csv                    actions/ helpers/ regression-tests/      engine/

And I guess it is the jacoco.xml that sonar jacoco looks at when I run sonar:sonar

I have the “JaCoCo XML report importer” version 1.0.0 installled. And I guess it is looking for jacoco.xml under directory I have specified in property <sonar.jacoco.reportPaths> Correct?

br,

//mikael


(Mikael Petterson) #4

So my questions are:

  1. Is it the jacoco.xml that should be transferred?
    2.How is it transferred to sonarqube? Can i see it in the log?

//mikael


(Mikael Petterson) #5

These are pointing to jacoco.exec files and not xml files. I am not sure when these properties are used?

//mikael


(Mikael Petterson) #6

I tried using a single jacoco.exec and sonar takes that directly. But when I have an jacoco.xml, that is what the report-aggregate generates, then it does not work. So there must be an error in the sonar-jacoco plugin.