“Project coverage is set to 0%” – JaCoCo and Sonar in Jenkins with Ant

I moved my job from a single Hudson machine to a multi-slave Jenkins environment, and now JaCoCo coverage no longer works.

WORKING (old):
Hudson 2.0.1,
Jenkins Sonar Plugin 1.7.1,
Sonar 2.1.2

  • How do I make Jenkins, Sonar and the JaCoCo plugin work together for Eclipse Tycho Plugin Projects (or maybe Cobertura)?
  • Jacoco and Sonar code coverage?
  • SonarQube not picking up Unit Test Coverage
  • How to attach JaCoCo Agent to application server
  • Use sonar to prevent a commit if code coverage QG is not met
  • Jacoco code coverage show 0% coverage on Jenkins
  • BROKEN (new):
    Jenkins 1.446,
    Jenkins Sonar Plugin 1.7.2,
    Sonar 2.1.2

    My Hudson job is called Pinnacle and it used to run on a single Hudson server with Sonar on the same machine. I set up my (NO MAVEN) build by doing the following.

    1) Added an Ant target to my build.xml called test-with-coverage

    2) Configured the Pinnacle job in Hudson to “invoke standalone Sonar Analysis” with these properties:

    sonar.projectKey=com.skyboximaging:pinnacle
    sonar.projectName="Pinnacle"
    sonar.projectVersion=1.0
    sources=Pinnacle/src/java
    tests=Pinnacle/test/java
    binaries=Pinnacle/classes
    sonar.jacoco.reportPath=Pinnacle/jacoco.exec
    sonar.jacoco.antTargets=test-with-coverage
    

    (Note that the code is checked out into Pinnacle directory in the Jenkins job workspace.)

    3) Configured Sonar “general settings” to use JaCoCo for code coverage

    Everything worked beautifully!

    But in the new Jenkins environment, I see this error in the Jenkins build output:

    23:15:17.863 INFO  Sensor JaCoCoSensor...
    23:15:17.868 INFO  Project coverage is set to 0% as no JaCoCo execution data has been dumped: /var/lib/jenkins/workspace/Pinnacle/Pinnacle/jacoco.exec
    

    That file does not exist on the slave where the build ran. (The directory /var/lib/jenkins/workspace/Pinnacle/Pinnacle does exist.)

    All other sensors (FindBugs, PMD, etc) appear to be working OK. Just JaCoCo is broken.

    Does Sonar/JaCoCo even work in a multi-slave Jenkins environment?

    I suspect that the Ant task test-with-coverage is not getting run. How does Sonar locate the build.xml? And what is different between old and new installations?

  • How to specify custom parameters, using xunit.runner.console
  • Jenkins Test Result Trend Graph Empty, but Tests Are Run
  • Jenkins configuration
  • jenkins git how pull instead of clone?
  • Perform jenkins build on local files
  • How to check out from svn and git in the same Jenkins job?
  • One Solution collect form web for ““Project coverage is set to 0%” – JaCoCo and Sonar in Jenkins with Ant”

    I’ve recently setup and successfully got Sonar and Jacoco running together. Since I’m recent with the topic, I figured I’d check on stackoverflow for similar issues and help out. I am getting results from Jacoco, but found you had to explicitly set the following parameters in addition to the properties you’ve listed in your post:

    sonar.core.codeCoveragePlugin=jacoco
    sonar.jacoco.reportPath=tests/jacoco-exec/jacoco.exec
    sonar.dynamicAnalysis=reuseReports
    sonar.surefire.reportsPath=tests/test-reports
    

    You have to set sonar.core.codeCoveragePlugin=jacoco if you want to be able to use the sonar.jacoco.reportPath property. Otherwise, you will have to use the sonar.jacoco.itReportPath property. However, I recommend just setting the codeCoveragePlugin and reportPath properties. Otherwise, it won’t display under the default coverage widget in sonar. Please make note, you cannot use the default coverage tool and jacoco together. It has to be one or the other. I decided to use Jacoco.

    Your ant target must be configured to generate the jacoco.exec results prior to running the sonar tasks:

    <jacoco:coverage enabled="${tests.code.coverage}" destfile="${jacoco.exec.dest}">
      <junit fork="yes" printsummary="withOutAndErr" dir="${tests.working.dir}">
      ...
    

    Be sure to tell sonar to reuse reports and any sunfire reports if you’re running junit before sonar, that is if you’re running junit outside of sonar:

    sonar.dynamicAnalysis=reuseReports
    sonar.jacoco.reportPath=tests/jacoco-exec/jacoco.exec
    sonar.surefire.reportsPath=tests/test-reports
    

    For whatever reason, if you need more verbose debugging, use the following property:

    sonar.verbose=true

    Git Baby is a git and github fan, let's start git clone.