Using Cobertura or Clover to generate code coverage reports is a relatively straightforward task as there have been some examples out there to begin with. On the other hand, being able to see coverage number generated by Clover in Sonar console takes a little bit extra configuration as Sonar by default is using Cobertura as code coverage plugin.
Ant Tasks Configuration
Sonar Ant target configuration(with dynamic analysis)
Sonar Ant target configuration(with reuseReports)
ant with.clover test clover.report sonar
(test target is the one to compile source code and run JUnit test, replace it with your own one)
Sonar Server Configuration
There was something I have been missing and kept me from seeing the code coverage number showing up in Sonar console after running the above mentioned Ant command. Despite already setting “sonar.core.codeCoveragePlugin” property to “clover”, I was still not able to see the coverage number. It turned out that the answer is right there in the Sonar Clover Plugin instruction.
What I was missing is adding Sonar Clover Plugin jar file into Sonar core-plugins directory.
It is also important to configure Sonar’s Global or Project settings to specify using “clover” as code coverage plugin.