Sonar and jacoco

I am a fan (and regular user) of Sonar, a platform to manage code quality.  The 2.12 release of Sonar, which happened yesterday, introduced a bunch of new features including Java 7 support and the availability of Jacoco into Sonar core. 

Though I had come across Jacoco earlier, I had ignored it.  I decided to look at what is Jacoco and why do we need yet another code coverage tool.  Their Mission page details the origin of the tool and the people behind it. 

I have been a regular user of Cobertura for command-line/maven based code coverage, and Eclemma for IDE-based.  I was curious to know if there was a jacoco maven plugin and to my delight, there indeed was one.

The usage instructions could have been better for I struggled to figure out the command to run to do the coverage analysis.  There are two goals, which are relevant jacoco:prepare-agent and jacoco:report

Merely including the plugin definition in the pom and running mvn jacoco:report gives an error.
[ERROR] Unable to read execution data file \target\jacoco.exec: \target\jacoco.exec (The system cannot find the path specified)
 Running mvn jacoco:prepare-agent jacoco:report is no better.

What is required is to run mvn jacoco:prepare-agent test jacoco:report

Alternately, I believe the plugin can be configured to run prepare-agent maybe in process-test-resources phase and jacoco:report in say, verify phase.

Sonar, by default, uses cobertura for code coverage.  It can be configured to use jacoco instead either globally or for specific project by going to Configuration -> General Settings  | Settings -> Code coverage and specifying jacoco key.

Jacoco reporting is similar to cobertura - in fact, in addition to XML and HTML reports, Jacoco also provides CSV report.

The next release of Eclemma uses jacoco.

Comments

Popular posts from this blog

Opening a safe deposit locker in SBI

Opening a Kannada Word document

When gas leaks