Instructions for Java Maven builds are incorrect

The instructions for adding the generation of coverage information to a (Java) Maven build miss a step. The prepare-agent goal will add the jacoco agent during the build, but will not cause the actual report to be generated after the tests. As a result, the coverage will always be reported as zero. The way that does work, is to also add the “report” goal during the “prepare-package” phase, because this is the report that the sonar scanner needs to read. I do not know how to accomplish this on the commandline, but the following in the pom works:


Hey there.

Can you point to the specific documentation you’re talking about?

Go to an organization that has pulled repos from GitHub, but (e.g. because they are Java projects) not analyzed them automatically. Follow instructions to set up a manual build for a Maven project, any CI tool. (or none)

The instructions shown are to adjust the Maven build with commandline parameters adding the jacoco agent and run an analysis. These instructions only add the agent, but no report is generated, so the Sonar scanner has no coverage info to import.

Bert Laverman

Hey Bert!

Indeed, I see this but only under Travis CI!

Do you see this on other CI tools? Do you have a screeenshot to share?

Actually, the “With other CI Tools” leaves out jacoco entirely:

As does the “Manually” version:

And the “CircleCI” version:

You can see why I double checked. :wink:

I wonder if this is intended to reflect a Travis CI convention rather than SonarCloud trying to guide you to setup Code Coverage (if I recall, Travis CI makes use of the .exec format of JaCoCo reports for its own reporting of coverage on the pipeline). I’ll poke around internally!

I put the changes I suggested in all our GitHub/Jenkins projects, and added the “-Pcoverage” profile to the build, followed by a separate run with the “sonar:sonar” goal. Only with the jacoco change is the report found.

I started out with the Travis-built AxonFramework projects, then adjusted those instructions to the Jenkins builds, but if I leave out jacoco bit altogether I get no coverage reporting in any of the builds.
(We are in the process of migrating from a private SonarQube instance to SonarCloud)