Could not get property 'test' on subproject

I have a multi-module project and using jacoco get a code coverage report across all subprojects.

Theres the task

task codeCoverageReport(type: JacocoReport) {
    dependsOn = subprojects.test
    // Gather execution data from all subprojects
    executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")

    additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
    sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)
    classDirectories.setFrom files(subprojects.sourceSets.main.output).collect {
        fileTree(dir: it, exclude: coverageExcludedClassDirectories)
    }
...
}

but when calling .gradlew build I get the error Could not get unknown property 'test' for project ':project-name' of type org.gradle.api.Project. even though there are tests defined. Without the dependency on the test the build still errors saying it cannot find the property ‘sourceSets’.

What can I do for the build to find the subproject properties?

Just don’t even try to do what you try to do.
This is highly unsupported and unsafe.
You need to use proper way to share outputs between projects as documented at Sharing outputs between projects.

But you could also simply use The JaCoCo Report Aggregation Plugin which does exactly what you intend, just the safe way documented at the link above. :wink: