3

I have a maven Jenkins job (Jenkins version 2.105) with Jacoco and Sonar (Version 6.0) configured. The project has multiple jacoco.exec created and I need to put the path for the same under sonar.jacoco.reportpath. The code coverage comes up in sonar if I add for only one exec. While adding the others are comma separted values, code coverage in not displayed in Sonar.

As the version of SonarQube is prior to 6.2 I understand we are required to use sonar.jacoco.reportPath property and not sonar.jacoco.reportPaths. How do we configure multiple path here?

  • What version of SonarJava are you using? You'll find it in Administration > System > Update Center – G. Ann - SonarSource Team Apr 04 '18 at 16:11
  • What if you try to pass the files as: /path/to/your/execFiles/**/*.exec or see few of the posts here to get more insight: https://stackoverflow.com/questions/18879250/jacoco-unit-and-integration-tests-coverage-individual-and-overall – AKS Apr 05 '18 at 18:19
  • 1
    Seems like you have to bump SQ API to a later version which supports sonar.jacoco.reportPaths (with `s`) and give comma separated list for it's value. Without that, sonar.jacoco.reportPath wont take comma separated exec files.. but see if *.exec helps (assuming if all exec files are sitting inside a single folder) – AKS Apr 05 '18 at 18:34
  • @ArunSangal : Yes, in order to use multiple jacoco.exec we need the later version of Sonarqube. After the upgrade I was able to set the paths and the collaborated result. Thanks a lot! – Sreelakshmy Koonath Apr 16 '18 at 09:01

1 Answers1

2

You need to merge your JaCoCo .exec files into a single binary file.

To achieve this use JaCoCo's merge mojo.

Cristian (from cristian.io) has an excellent walkthrough of how to achieve this here. The following is a slightly modified version of the code from that blog post.

def allTestCoverageFile = "$buildDir/jacoco/allTestCoverage.exec"

task jacocoMergeTest(type: JacocoMerge) {
  destinationFile = file(allTestCoverageFile)
  executionData = project.fileTree(dir: '.', include:'**/build/jacoco/test.exec')
}

sonarqube {
  properties {
    property "sonar.projectKey", "your.org:YourProject"
    property "sonar.projectName", "YourProject"
    property "sonar.jacoco.reportPath", allTestCoverageFile
  }
}
Pranav
  • 666
  • 8
  • 8