How do I make Jenkins, Sonar and the JaCoCo plugin work together for Eclipse Tycho Plugin Projects (or maybe Cobertura)?

danowar picture danowar · Jan 20, 2012 · Viewed 9.1k times · Source

my setup is:

  • Jenkins 1.448
  • Sonar 2.13
  • Jenkins Sonar Plugin 1.72
  • a MySql database for Sonar

I have the following project:

  • Eclipse Plugin Project
  • using Maven
  • multiple modules (parent maven project, source plugin project, test fragment project)
  • a simple JUnit test testing a class of the source plugin project

What the process is at the moment:

  • Jenkins checks out the parent project from SVN
  • Jenkins builds the project and its modules using Maven and Tycho
  • Jenkins uses Surefire to execute the tests and produce a report
  • Jenkins uses the Jenkins Sonar plugin to start mvn sonar:sonar to execute code analysis
  • Static code analysis is done on each module
  • JaCoCo fails

Sonar has static code analysis statistics available and test success percentage is shown. The only thing that's missing is JaCoCo's code coverage...or maybe even Cobertura's code coverage.

I don't really care at this point, I just want one of these things to produce code coverage results.

Cobertura seems to be unable to produce results possibly because either - it can't instrument the code - it looks for the instrumented code at the wrong place - it can't cope with Tycho or the separate source/test code setup

JaCoCo should be able to "watch" the code coverage on the fly, but its output is

[INFO] [17:44:04.708] Sensor JaCoCoSensor...
[INFO] [17:44:04.717] Project coverage is set to 0% as no JaCoCo execution data has been dumped: /var/lib/jenkins/jobs/testPlugin/workspace/testSource/target/jacoco.exec
[INFO] [17:44:04.854] Sensor JaCoCoSensor done: 146 ms

[INFO] [17:44:10.587] Sensor JaCoCoSensor...
[INFO] [17:44:10.587] Project coverage is set to 0% as no JaCoCo execution data has been dumped: /var/lib/jenkins/jobs/testPlugin/workspace/testTest/target/jacoco.exec
[INFO] [17:44:10.631] Sensor JaCoCoSensor done: 44 ms

[INFO] [17:44:12.402] Sensor JaCoCoSensor...
[INFO] [17:44:12.402] Project coverage is set to 0% as build output directory doesn't exists: /var/lib/jenkins/jobs/testPlugin/workspace/testParent/target/classes
[INFO] [17:44:12.402] Sensor JaCoCoSensor done: 0 ms

What am I doing wrong? Do I need to enable JaCoCo in my pom.xml somewhere? Do I need surefire? What do I need to do to use Cobertura?

Answer

danowar picture danowar · Jan 27, 2012

I've found a page with an example tycho multi-module project (separate source and test projects). After copying some of the properties and configurations...

it seems that I now use a maven jacoco plugin to generate the jacoco code coverage report and then tell Sonar where to find the report and reuse it.

Why on earth is there next to no documentation for this? Or why is it so hard to find?

https://github.com/Godin/sonar-experiments/tree/master/jacoco-examples/tycho-example