Could not get unknown property 'reports' for object of type org.gradle.api.internal.tasks.RealizableTaskCollection

Hi. I am completely new to Gradle but inherited a build job with the following fragment in build.gradle, which I’m told used to work fine till some upgrade:

subprojects {
sonarqube {
properties {
if(project.pluginManager.hasPlugin(‘java’)) {
def tests = project.sourceSets.findAll {‘test|testIntegration|functionalTest’) }

            def testTasks = project.tasks.withType(Test.class)
            def junitReports = testTasks.reports.junitXml.destination.findAll { it.exists() } ;

At this point it now fails with ERROR: “Could not get unknown property ‘reports’ for object of type org.gradle.api.internal.tasks.RealizableTaskCollection”

So far I’m guessing:
testTasks type is: org.gradle.api.tasks.testing.Test
reports - org.gradle.api.tasks.testing.AbstractTestTask#getReports
junitXml - org.gradle.api.tasks.testing.TestTaskReports#getJunitXml
destination - org.gradle.api.reporting.DirectoryReport#getDestination
findAll - org.codehaus.groovy.runtime.DefaultGroovyMethods#findAll(java.util.List, groovy.lang.Closure)

From the error it almost seems the collection must be iterated first, before getting the files… Or that the “new” return type RealizableTaskCollection does not contain getReports() but the “old” one used to?

Any ideas about what may have happened or how to go about debugging this are appreciated. Happy New Year!

As you’ve disovered, project.tasks.withType(Test.class) returns a TaskCollection (and always has).

Perhaps the code used to use Groovy’s spread-dot operator?

def junitReports = testTasks*.reports.junitXml.destination.findAll { it.exists() }
//                          ^
1 Like

This worked great, your suggestion with the asterisk “*”. No one recalls that ever being there, I could not find that in commit history, but what’s most important is that my issue is solved by you. Thank you!