1

I have a standalone Jenkins job to run Sonar on our codebase, which works fine, but I am consistently getting code coverage of zero despite the fact that the post-processing job correctly displays the code coverage in Jenkins. I think the issue is with Sonar not picking up the exec files correctly, as I am receiving this in the Jenkins logs:

INFO: Analysing D:\Data\CCS\Jenkins\jobs\Sonar Scan\workspace\ccs-core\target\jacoco.exec
INFO: Analysing D:\Data\CCS\Jenkins\jobs\Sonar Scan\workspace\ccs-core-common\target\jacoco.exec
INFO: Analysing D:\Data\CCS\Jenkins\jobs\Sonar Scan\workspace\ccs-core-client\target\jacoco.exec
INFO: No JaCoCo analysis of project coverage can be done since there is no class files.

Despite the fact that I can see that the files are in that location after the job has completed.

I have two steps in the build, the first is to run Jacoco via mvn:

clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=true

the second just uses the Sonar plugin to generate the report. Then there is the post-processing report that generates the Jacoco report in Jenkins.

Could some helpful soul point me to what I might be missing?

1 Answers1

0

Try This :

In pom.xml

    <properties>
<jacoco.data.file>${project.build.directory}/coverage-reports/jacoco.exec</jacoco.data.file>
...
</properties>

        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <executions>

                <execution>
                    <id>default-prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <destFile>${jacoco.data.file}</destFile>
                        <propertyName>surefireArgLine</propertyName>
                    </configuration>
                </execution>
                <execution>
                    <id>post-unit-test</id>
                    <phase>test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <dataFile>${jacoco.data.file}</dataFile>
                        <outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
                    </configuration>
                </execution>
                    ...
                    ...

And in sonar-projet.properties

sonar.jacoco.reportPath=coverage-reports/jacoco.exec
G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
question_maven_com
  • 2,457
  • 16
  • 21
  • This won't work, as the project structure is a bit weird with sub pom.xml files. My config file looks like: # Comma-separated paths to directories with sources (required) sonar.sources=ccs-core/src, ccs-core-client/src, ccs-core-common/src sonar.binaries=ccs-core/target/classes, ccs-core-client/target/classes, ccs-core-common/target/classes # Test coverage location sonar.jacoco.reportPaths=ccs-core/target/jacoco.exec, ccs-core-client/target/jacoco.exec, ccs-core-common/target/jacoco.exec – Thomas Brooman Mar 22 '17 at 16:35
  • This won't work, as the project structure has sub projects with their own poms. I think that's basically the problem. I did run across this: http://stackoverflow.com/questions/27778752/how-can-i-integrate-jacoco-reports-with-sonarqube-without-using-maven which stated that I needed to set the sonar.binaries property, but that's still failing with the same error. I don't know whether I need to specify sonar.junit.reportsPath as well, or whether I can specify it with multiple paths as comma-seperated values to each of my sub-projects. – Thomas Brooman Mar 22 '17 at 16:42
  • Yes, I can't add multiple paths for sonar.junit.reportsPath. I suspect I'm simply not able to do this because I need to specify each of these modules seperately. – Thomas Brooman Mar 22 '17 at 16:44
  • Sonar will be executed on each sub project. So set the paths in relation to the pom (sub module). sonar.jacoco.reportPath=target/jacoco.exec – Christopher Mar 22 '17 at 22:20