sonarqube gradle plugin excluding jacoco integration tests
Asked Answered
H

2

8

I'm trying to integrate the sonarqube gradle plugin with the jacoco plugin:

classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.1'

apply plugin: 'org.sonarqube' apply plugin: 'jacoco'

My build/jacoco folder contains: integrationTest.exec test.exec

However, the sonarqube plugin only recognises the 'test.exec' file:

18:20:45.130 INFO - JaCoCoItSensor: JaCoCo IT report not found: C:\Users\abc3\Downloads\sme-letter\target\jacoco-it.exec : 18:05:55.609 INFO - Analysing C:\Users\abc3\Downloads\sme-letter\build\jacoco\test.exec

How do I get the sonarqube plugin to recognise 'integrationTest.exec'

Thanks

Mark

Harrier answered 26/10, 2016 at 7:22 Comment(1)
Is 'build/jacoco/integrationTest.exec' something standard? I was not aware of a built in support of integration tests in Gradle. Would you mind sharing a sample project in SonarQube user group? If this is something standard we could improve the SonarQube Scanner for Gradle to support it out of the box.Fendley
G
3

I'm not really sure, whether this will work for Gradle plugun, but you may try.

Sonar has a property to specify the name of the integration tests JaCoCo report. This property is called sonar.jacoco.itReportPath (sonar.jacoco.reportPath for unit tests report).

And as far as I know, gradle sonar plugin let you add custom properties to it. So you can change IT report name via properties as follows:

sonarqube {
    properties {
        property "sonar.jacoco.itReportPath", "build/jacoco/ integrationTest.exec"
    }
}
Glossal answered 26/10, 2016 at 7:38 Comment(2)
I confirm the SonarQube Scanner for Gradle only consider the "unit test" coverage report.Fendley
So is there any way we can add "it report" coverage report. It was working with maven, it shouldn't be too hardUrson
U
1

It works for me, but only after merging all jacoco reports into one file AND (important) deleting all other reports

        property "sonar.java.coveragePlugin", "jacoco"
        property "sonar.junit.reportsPath", "$projectDir/build/test-results"
        property 'sonar.jacoco.reportPaths', "${rootProject.buildDir}/jacoco/mergeJacoco.exec"

And you need a merge jacoco task

Task mergeJacoco = tasks.create('mergeJacoco', JacocoMerge, {
  doFirst {
      delete "$buildDir/jacoco/mergeJacoco.exec"
  }
  destinationFile(new File(buildDir, 'jacoco/mergeJacoco.exec'))
  executionData fileTree('./').include('**/*.exec-partial')
  doLast {
      delete fileTree('./').include('**/test.exec-partial')
  }
})

mergeJacoco.outputs.upToDateWhen { false }
project.tasks["sonarqube"].dependsOn mergeJacoco
mergeJacoco.mustRunAfter ":myProject:test"

And setup jacoco to use those "partial" files

subprojects {
    ....
    jacoco {
        destinationFile file("$buildDir/jacoco/test.exec-partial")
        append = false
        includes = ['com.mypackage.*']
    }
}

You'll get unit and IT reports mixed in one, but that's the best I could get

Urson answered 15/2, 2018 at 8:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.