Sonar can't find generated SCC test's sources in Gradle's build directory

I’m using SCC (Spring Cloud Contract) for integration testing and I want to show in section “Coverage” of Sonar’s Dashboard count of my unit + SCC tests.

I’ve tried to add directory build/generated-test-sources/contracts , where SCC’s Java-sources stored after generation, to sonar.tests property, but it doesn’t helped - I’ve still seeing only count of my unit-tests in Sonar’s Dashboard:

 sonarqube {
    properties {
        property "sonar.host.url", "http://localhost"
        property "sonar.projectKey", "myProject"
        property "sonar.sources", "src/main/java"

        property "sonar.sourceEncoding", "UTF-8"
        property "sonar.language", "java"
        property "sonar.login", "abracadabra"
        property "sonar.tests", "src/test/java, build/generated-test-sources/contracts"
    }
}

I’ve created a Gradle switch: if there is sonarqube task in task graph, then SCC’s output folder will be src/test/java/generated . After end of sonarqube task, this directory will be deleted:

contracts {
    baseClassForTests = "myProj.BaseTest"
    testMode = "EXPLICIT"
    testFramework = "JUNIT5"
    gradle.taskGraph.whenReady { taskGraph ->
        if (taskGraph.hasTask(":sonarqube")) {
            generatedTestSourcesDir = project.file('src/test/java/generated')
        }
    }
}

task deleteGeneratedContractTests(type: Delete) {
    delete 'src/test/java/generated'
}

project.tasks["sonarqube"].finalizedBy "deleteGeneratedContractTests"

Now both unit and SCC tests count shows in Sonar’s Dashboard, but my solution, as it seems to me, is a bit ugly: is there a way to configure Sonarqube plugin without creating/deleting directories in src/?

Versions:

  • org.sonarqube 3.0
  • org.springframework.cloud.contract 2.2.3