Hello,
I am currently trying to setup jacoco in a multi build project, however, run into some problems concerning the build path and are therefore looking for help.
I set up a small plugin in the build-logic to provide a common configuration for all projects that use jacoco. Here, I also want to modify the report directory of the xml, html, and csv reports. I figured out I need to configure this lazy, as I change the build directory for some builds in their respective build file. The resulting plugin looks like this:
plugins {
`java`
`jacoco`
}
tasks.jacocoTestReport.get().reports.csv.required.set(true)
tasks.jacocoTestReport.get().reports.html.required.set(false)
tasks.jacocoTestReport.get().reports.xml.required.set(true)
tasks.jacocoTestReport.get().reports.csv.outputLocation.set(layout.buildDirectory.file("/reports/test-coverage/jacoco.csv"))
tasks.jacocoTestReport.get().reports.html.outputLocation.set(layout.buildDirectory.dir("/reports/test-coverage/jacoco/html"))
tasks.jacocoTestReport.get().reports.xml.outputLocation.set(layout.buildDirectory.file("/reports/test-coverage/jacoco.xml"))
tasks.test.get().finalizedBy(tasks.jacocoTestReport)
tasks.jacocoTestReport.get().dependsOn(tasks.test)
This works fine locally. All projects that use this plugin produce files as expected in the “build/reports/test-coverage/” or similar for those that update their build path.
However, this does not work in a gitlab ci environment. Here, it seems that the default build path is only set after execution of the jacoco test report task. Files are generated into “/reports/test-coverage/”.
Printing the build path to command line after task execution via
tasks.getByName<JacocoReport>("jacocoTestReport").doLast {
this as JacocoReport
println("CSV report dir: " + this.reports.csv.outputLocation.get())
println("XML report dir: " + this.reports.xml.outputLocation.get())
println("Build dir: $buildDir")
}
produces these results:
CSV report dir: /reports/test-coverage/jacoco.csv
XML report dir: /reports/test-coverage/jacoco.xml
Build dir: PROJECT_DIR/build
(with RPOJECT_DIR being a placeholder for the respective dir of the subproject)
Any ideas/input is highly appreciated.