Slackbot
01/12/2024, 4:06 PMAlexander Volanis
01/12/2024, 4:08 PMAnze Sodja
01/12/2024, 4:17 PMonlyIf {
this.getXmlReport().get().asFile.exists()
}
maybe this could fix it:
def xmlReport = this.getXmlReport()
onlyIf {
xmlReport.get().asFile.exists()
}
Alexander Volanis
01/12/2024, 4:20 PMAlexander Volanis
01/12/2024, 4:21 PMAlexander Volanis
01/12/2024, 4:22 PMAnze Sodja
01/12/2024, 4:25 PMonlyIf { task ->
task.xmlReport.get().asFile.exists()
}
Vampire
01/12/2024, 4:50 PMJacocoReport
task that you give all execution data files for what you want a combined report conceptually like the JaCoCo report aggregation plugin does. You just need some extra configuration if you want a report over different test types, but that is what I do to get an overall JaCoCo report.Ryan Schmitt
01/12/2024, 6:23 PMJacocoReport
task?Vampire
01/12/2024, 6:47 PMRyan Schmitt
01/12/2024, 6:48 PMVampire
01/12/2024, 6:49 PMRyan Schmitt
01/12/2024, 6:56 PMonlyIf
can close over xmlReport
but not this
Vampire
01/12/2024, 7:56 PMonlyIf new Spec() {
@Override
boolean isSatisfiedBy(Object o) {
this.getXmlReport().get().asFile.exists()
}
}
Vampire
01/12/2024, 7:57 PM@CompileStatic
would also have worked.Alexander Volanis
01/13/2024, 8:16 PMJacocoCoverageSummaryReportTask.groovy: 50: [Static type checking] - Cannot statically compile constructor implicitly including non-static elements from fields, properties or initializers
@ line 50, column 5.
@CompileStatic
^
I tried to make sure all references to fields are qualified but nothing worked.Alexander Volanis
01/13/2024, 8:17 PMonlyIf { JacocoCoverageSummaryReportTask task ->
task.xmlReport.get().asFile.exists()
}
Ryan Schmitt
01/13/2024, 8:18 PMRyan Schmitt
01/13/2024, 8:19 PMAlexander Volanis
01/13/2024, 8:22 PMdoLast
in my opinion. But perhaps worth refactoring into such?
Basically the entire @TaskAction of this task could become an attached doLast action for each JacocoReport task. The one at the root project does the aggregation. To do this right we would need to adjust the task outputs of the JacocoReport but that is probably just as easy.Ryan Schmitt
01/13/2024, 8:22 PMAlexander Volanis
01/13/2024, 8:24 PMRyan Schmitt
01/13/2024, 8:27 PMRyan Schmitt
01/13/2024, 8:27 PMAlexander Volanis
01/13/2024, 8:28 PMAlexander Volanis
01/13/2024, 8:29 PMAnze Sodja
01/15/2024, 9:02 AMAnze Sodja Can you explain how you spotted that so easily? It seems like there's a lot of Groovy-specific stuff going on here, because it's not obvious to me why onlyIf can close over xmlReport but not thisIt's far from obvious. We should have less of such traps. First hint for me was, using `onlyIf`:
onlyIf
runs at the execution time, always even on cc hit and because of that closure is serialized. So onlyIf
is very similar to doFirst/doLast
in that regard.
And then org.gradle.api.specs.internal.ClosureSpec.isSatisfiedBy(ClosureSpec.java:33)
, isSatisfiedBy
was a good hint that this is in fact onlyIf
closure.
And then using this.
that have a reference to a larger scope (whole task in that case). Although it was not obvious to me that this causes an issue.
It seems that similar code works in Kotlin, so it's really a quirk in Closure serialization.Alexander Volanis
01/16/2024, 5:37 PMthis
was an attempt to clear up the issue. I was not using this
before I ran into the problem. But your explanation makes sense now and solved the immediate issue. Long term I am converting this to use Java instead of Groovy eliminating Closure serialization for good.