I would like to share my first experiment of test coverage for a multi-module maven project with sonar and JaCoCo.

Prerequisites :

  • sonar 2.3
  • sonar JaCoCo plugin 0.2
  • maven 2
  • Sample project :

    I have a multi-module project with the following structure:


    This example was generated from seam-ear-archetype ( http://code.google.com/p/open-archetypes/ )

    Setps of experiment :

    1) Unzip the sample project : multimodulecoverage.zip
    2) Download the jacoco agent from ${your_sonarserver_url}/deploy/plugins/jacoco/agent-all-
    3) Compile and test projects:

    mvn clean  test -DargLine="-Dsun.lang.ClassLoader.allowArraySyntax=true -Xms512m -Xmx512m -javaagent:D:\Users\jer\agent-all-,append=true,includes=org.printstacktrace.*,excludes=*_javassist_*"

    4) Generate the sonar information without test:

    mvn sonar:sonar -Dsonar.core.codeCoveragePlugin=jacoco -Dsonar.jacoco.itReportPath=..\target\itjacoco.exec -Dmaven.test.skip

    5) Inspect the sonar server pages:

    It works!

    Conclusions :

  • Thanks to the sonar team for this plugin.
  • The data is in section it covergae tab, because we use « itReportPath » to merge the informations.
  • We must manually download and configure the agent.
  • So, waiting for the next version of the JaCoCo sonar plugin.