Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple paths in sonar.jacoco.reportpath

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?

like image 387
Sreelakshmy Koonath Avatar asked Feb 07 '26 12:02

Sreelakshmy Koonath


1 Answers

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
  }
}
like image 133
Pranav Avatar answered Feb 09 '26 12:02

Pranav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!