Diffcoverage fails with Empty File Collection if Clean is used
Describe the bug
When running a task like:
./gradlew clean testDebugUnitTestCoverage diffCoverage --no-build-cache
And configuring where the location of the class files can be found. Diff Coverage will through an error:
- What went wrong: Could not determine the dependencies of task ':lib:diffCoverage'.
'diffCoverageReport.classesDirs' file collection is empty.
This is becuase the clean will have wiped out the location of the files and the configuration happens before the files are loaded.
Currently:
https://github.com/form-com/diff-coverage-gradle/blob/master/diff-coverage/src/main/kotlin/com/form/coverage/gradle/DiffCoverageTask.kt#L38
calls collectFilesOrThrow which eagerly collects the files instead of lazily doing it after the configuration phase has completed.
Ideally these should take Providers instead of FileCollections directly, so that when the task is executing it can get the files at that particular time instead of eagerly doing it whenever the get method is called.
https://github.com/form-com/diff-coverage-gradle/blob/980b305dbf28aad41020f9be018344d43652a90c/diff-coverage/src/main/kotlin/com/form/coverage/gradle/DiffTaskAutoConfiguration.kt#L6
That will always throw an error if clean is used. If clean is not used and the coverage has run before as a seperate step it'll pass.
Ideally a FileCollectionProvider should be used and read from the ReportGenerator.
Desktop (please complete the following information):
- OS: all
- Gradle version: 7.4.1
- Diff Coverage plugin version: 0.9.3
To Reproduce
./gradlew clean jacocoReport diffCoverage
Works if:
./gradlew clean jacocoReport ./gradlew diffCoverage
Expected behavior
./gradlew clean jacocoReport diffCoverage
should work without crashing
A clear and concise description of what you expected to happen.
Logs
Could not determine the dependencies of task ':lib:diffCoverage'.
'diffCoverageReport.classesDirs' file collection is empty.
Seems related to #43 . @SurpSG May I know if the fix has been merged into latest version (0.9.5)?
Hi @grsky360
I'm planning to release 1.0.0 that fixes the issue but the release is not ready yet.
As workaround we could set explicit dependency on classes tasks:
diffCoverage.dependsOn subprojects.classes
getting the following error when using the plugin for an android project.
Could not get unknown property 'classes' for project ':app' of type org.gradle.api.Project.
@adityameesho please provide stacktrace
./gradlew diffCoverage -s
I solved it by creating a new step in my CI server
basically ./gradlew jacocoReport diffCoverage was failing
using a 2 step CI command like this worked
// 1st step in CI
./gradlew jacocoReport
// 2nd step in CI
./gradlew diffCoverage