Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 872
danowar Avatar asked Jan 20 '12 16:01

danowar


2 Answers

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

like image 117
danowar Avatar answered Sep 20 '22 15:09

danowar


You can have a look on the blog post I wrote few months ago : http://mdwhatever.free.fr/index.php/2011/09/quality-analysis-on-eclipse-plugins-with-tycho-sonar-jacoco-and-swtbot/

like image 32
xavier.seignard Avatar answered Sep 21 '22 15:09

xavier.seignard