I would like to merge the coverage of many of my included project of a composite build. But only some of them have a coverage.
1st, I create task for all of my included project in order to copy the potential jacoco exec file
Something like
gradle.includedBuilds.each { p -> tasks.register("copyCoverage${p.name}", Copy, { from ("${p.projectDir.path}") { include "**/*.exec" exclude '**/jacocoMerge.exec' includeEmptyDirs = false } into coverageDir + File.separator + p.name }) }
Then, I wrote a task for merge all of them
task jacocoMerge(type: JacocoMerge, group: 'Coverage reports') { group = 'CDR' dependsOn copyCoverage description = 'Merge all jacoco execution data from all java sub-projects into on execution file.' gradle.includedBuilds.each { p -> executionData (tasks."copyCoverage${p.name}".destinationDir) } }
But, as some of my project doesn’t have any exec file (=no output files for some of my copyCoverage{}), the jacocoMerge task failed with “Unable to read [… one of the destinationDir …]”
If I try to protect it by
gradle.includedBuilds.each { p -> def f = tasks."copyCoverage${p.name}".destinationDir if(f.exists()) { println "copy from ${f.absolutePath}" executionData (tasks."copyCoverage${p.name}".destinationDir) } }
I think I disable the lazy configuration and I have “No value has been specified for property ‘executionData’.”
How should I handle this issue ?