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:
<profiles>
<profile>
<id>coverage</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>