Configure Clover and Sonar Ant Tasks for Code Coverage

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)

Clover Ant target configuration

Ant Command

ant   with.clover   test   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.

Configure Clover and Sonar Ant Tasks for Code Coverage

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s