Gradle 3.3 and later cleanTest deletes jacoco exec files

Hi everybody.

we currently using gradle 3.4 with jacoco 0.7.7.201606060606 and SonarQube in a multi project environment. Since January 2017 we have a small unit test code coverage displayed in SonarQube. After doing some research we figured out, that some projects running a cleanTest gradle task before running the test task.
When running cleanTest the jacoco exec file filled with data from projects executed before gets deleted and a new exec file is created by the project running cleanTest and test. I created a sample project and figured out, that gradle 3.2.1 did not remove the jacoco exec file. Since gradle 3.3 the file is removed, when running cleanTest.

So my question is, what i have to do, to prevent jacoco exec files to be removed when cleanTest is executed?

Hi @pschwarzer-tt

This is due to registering the Jacoco exec file as an output to the Test task so that it will be included as an output with the build cache.

It sounds like you have your build configured so that all of the projects write to the same jacoco exec file? This isn’t the way it works by default. All of the Test tasks should be writing to separate files.

If you need all of the project’s coverage information in one file, I think you can accomplish a similar thing with JacocoMerge.

Hi,

thanks for your reply.

Yes, we have configured our build writing in one Jacoco exec file. We will try to reconfigure so each project will write in a separate Jacoco exec file.

Hi,

we tried to create separate Jacoco exec files for each project without success.

It seems, the current gradle sonar plugin from Gradle - Plugin: org.sonarqube did not support the new “sonar.jacoco.reportPaths” property. When running sonarqube task in gradle, i always got the warning “Property ‘sonar.jacoco.reportPath’ is deprecated. Please use ‘sonar.jacoco.reportPaths’ instead.”

Here my gradle log when running clean sonarqube

[sts] -----------------------------------------------------
[sts] Starting Gradle build for the following tasks:
[sts] clean
[sts] sonarqube
[sts] -----------------------------------------------------
:clean
:compileJava
:processResources NO-SOURCE
:classes
:compileTestJava
:processTestResources NO-SOURCE
:testClasses
:test
:sonarqube
Property ‘sonar.jacoco.reportPath’ is deprecated. Please use ‘sonar.jacoco.reportPaths’ instead.

BUILD SUCCESSFUL

Total time: 6.456 secs
[sts] -----------------------------------------------------
[sts] Build finished succesfully!
[sts] Time taken: 0 min, 6 sec
[sts] -----------------------------------------------------

In my build.gradle i did not use ‘sonar.jacoco.reportPath’, instead i use:

sonarqube {
properties {
property “sonar.jacoco.reportPaths”, “”

plugins.withType(JavaPlugin) {

sonarqube {
properties
{
properties[“sonar.jacoco.reportPaths”] += “${buildDir}/jacoco/unittest.jacoco.exec”
}
}

jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.destination “${buildDir}/jacoco/jacocoHtml”
}
}

test {
jacoco {
append = false
destinationFile = file(“${buildDir}/jacoco/unittest.jacoco.exec”)
classDumpDir = file(“${buildDir}/jacoco/unittest.classDumps”)
}
}
}

When sonar gradle plugin will support “sonar.jacoco.reportPaths”?