Jacoco report don't show on SonarQube

Hello there,

I am new to SonarQube, and I was asked in the scope of my studies to put in place measures.

I decided to make my code coverage report with Jacoco and the feed SonarQube with it (for testing reasons, i am making HTTP requests to my own services and need to track the associated code coverage). I’m on this since few days now and can’t figure out what’s the problem.

When I am packaging, testing, and the scanning my project, I successfully build the Jacoco Report wich is located on my file system, and the sonarQube server we use correctly get all others data (Failures, bugs, etc.). But the reports isn’t take in account on SonarQube.

Jacoco Report :

And then, in SonarQube, I get à 0% coverage on all files.

I followed this tread and the sonarQube documentation to build my pom.xml file. Here are the porperties I use. It is voluntary simplified to remove other dependencies’ settings.

<properties>
   <!-- Maven compiler properties -->
   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   <maven.compiler.source>1.8</maven.compiler.source>
   <maven.compiler.target>1.8</maven.compiler.target>
   
   [...]

   <!-- SonarQube properties -->
   <sonar.sources>src/main</sonar.sources>
   <sonar.tests>src/test</sonar.tests>
   <sonar.projectKey>an_id</sonar.projectKey>
   <sonar.host.url>an_url</sonar.host.url>
   <sonar.login>a_login</sonar.login>
   <!-- Sonar-JaCoCo properties -->
   <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
   <sonar.language>java</sonar.language>
   <sonar.coverage.jacoco.xmlReportPaths>target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>

Then I configure the maven profile to use Jacoco and make reports on execution as asked.

<profiles>
    <profile>
      <id>coverage</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.2</version>
            <executions>
              <execution>
                <id>prepare-agent</id>
                <goals>
                  <goal>prepare-agent</goal>
                </goals>
              </execution>
              <execution>
                <id>report</id>
                <goals>
                  <goal>report</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

Seeing the SonarQube documentation and the tread mentionned before, they said :

“By default the generated report will be saved under target/site/jacoco/jacoco.xml ; this location will be checked automatically by the sonar-jacoco plugin so no further configuration is required. Just launch mvn sonar:sonar as usual and the report will be picked up.”

And that’s exactly what i’m doing. :thinking:

Please note that i have a “Missing blame information for the following files:” warning during the sonar process, but i do not think it is linked.

Also, please note that the command i am using is :

mvn clean package verify sonar:sonar 

If needed, here is my complete pom file :
pom.txt (5.2 KB)

It is the only pom i have in my project, and actually my project is mono-module.

Thanks for reading and for your help !

Regards,
Kevin.

Hi Kevin,

When using maven, the only sonar.* properties you should truly need to specify are these:

The rest should be assumed from defaults and/or derived from the effective pom at the time of the analysis. Your usage of sonar.sources and sonar.tests in particular may be causing a mismatch between the paths reported in the jacoco report and the paths of sources/tests as seen by SonarQube.

We have an example single-module maven project on github where you can see we specify zero analysis parameters in the pom.xml. The project key is based on the group & artifact identifiers by default, and in this example we’d pass the host url and login on the command line rather than hardcoding in the pom file.

Hope this helps!

Hi,

Firstly, thanks you for your answer !

Sadly, it didn’t worked. :frowning:

Just to be sure I removed all sonar.* properties in maven and only specified host url, login, and project key by the CLI using -Dsonar at the mvn execution, but I still got a 0% coverage on sonarQube.

Do you have any other ideas ?

Many thanks,
Kevin.

EDIT :

Hey little update.
So I ran mvn with the -X flag to have debugs infos.

I found the following lines :

[INFO] 10:58:39.950 ------------- Run sensors on project

[DEBUG] 10:58:39.954 'Generic Coverage Report' skipped because one of the required properties is missing

I’m quite not sure it is linked because there is plenty of information here but that seems a possibility.
On the other hand I searched for a Sensor JaCoCo XML Report Importer [jacoco] or Reading report as mentioned under the “Troubleshooting” section of this tread but couldn’t find them !

It would be useful to see a content of the target/site/jacoco/jacoco.xml file and analysis logs :slight_smile:

Hey there ! :slight_smile:

I am sorry for the late answers, i had a few hard exams days.

Please find below my jacoco.xml and a log file.
Sorry that the log file isn’t easily readable ! Seems like maven color management introduce some kind of non-recognizable ASCII characters…
Also sorry, i cannot upload .XML files here, so i made a txt one, wich is really less convenient…

logs.txt (12.9 KB)
jacoco.txt (12.5 KB)

Thanks for your help !
Have a nice week,
Kevin.

I don’t see in your log message the following line:

[INFO] Sensor JaCoCo XML Report Importer [jacoco]

Did you install Sonar JaCoCo plugin on your SonarQube server?

Yes that line is missing !

We share a classroom server that should have been configured for us, i do not have the hand on that, but it may not have been for Jacoco yes !

I’ll ask and come back to you, that aspect totally got out of my mind.

Thanks you,
Kevin.

Hi @Kevin_Heirich,

To check if you have the JaCoCo plugin, you probably have access to:
https://quality.cross-systems.ch/api/plugins/installed

And by default on SonarQube 8.3.1 you should find:

  • "description":"JaCoCo XML report importer","version":"1.1.0 (build 898)"
  • "description":"Code Analyzer for Java","version":"6.3 (build 21585)"

Then you can run mvn -X sonar:sonar to see [DEBUG] messages like:

[INFO] 13:04:56.721 Sensor JaCoCo XML Report Importer [jacoco]
[INFO] 13:04:56.722 1/1 source files have been analyzed
[INFO] 13:04:56.722 Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
[DEBUG] 13:04:56.722 Reading report '/tmp/support/jacoco-example1/jacoco-m1/target/site/jacoco/jacoco.xml'
[INFO] 13:04:56.723 Sensor JaCoCo XML Report Importer [jacoco] (done) | time=2ms

Hey,

I am sorry, the problem was solved but I forgot to get here sending the answer.

The problem was that the JaCoCo plugin was missing on the server-side, the installation solved everything.

Thank’s everyone for your support !

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