Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube - no JaCoCo execution data has been dumped

I'm running SonarQube in a jenkins job (using Post-build Actions). I'm getting the following problem with JaCoCo -

[INFO] [16:57:43.157] Sensor JaCoCoSensor...
[INFO] [16:57:43.157] Project coverage is set to 0% as no JaCoCo execution data has been dumped: /var/lib/jenkins/.../target/jacoco.exec
[INFO] [16:57:43.426] Sensor JaCoCoSensor done: 269 ms

As a result, I'm getting 0% code coverage for my project. Couldn't find why jacoco.exec is not being created.

I don't have "JaCoCo" configured to run by maven (in my pom.xml). I know that in the past the jacoco.exec was created anyway (probably by Sonar itself).

What am I doing wrong? Do I need to configure JaCoCo in my pom.xml for it to work? Thanks.

like image 221
Moshe.z Avatar asked Apr 06 '14 15:04

Moshe.z


2 Answers

From the web Java Ecosystem:

It is no longer possible to let SonarQube drive the execution of the unit tests. You now have to generate the JUnit and code coverage (JaCoCo or Cobertura or Clover) reports prior to the SonarQube analysis and then feed SonarQube with those reports.

So you need to include Jacoco in the pom.xml:

   <plugin>
       <groupId>org.jacoco</groupId>
       <artifactId>jacoco-maven-plugin</artifactId>
       <version>0.7.0.201403182114</version>
   <configuration>
       <destFile>${basedir}/target/jacoco-unit.exec</destFile>
       <dataFile>${basedir}/target/jacoco-unit.exec</dataFile>
   </configuration>
       <executions>
           ...
       </executions>
   </plugin>

And give this data file to SonarQube:

sonar.jacoco.reportPath=target/jacoco-unit.exec
like image 89
utrescu Avatar answered Sep 26 '22 22:09

utrescu


According to this blog you can enable the creation of jacoco.exec files by adding the following plugin section to your pom.xml (it worked for me):

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.1.201405082137</version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
    </executions>
</plugin>
like image 38
dokaspar Avatar answered Sep 24 '22 22:09

dokaspar