Closed simonhauck closed 5 months ago
Gradle does not know how file 'build/ktfmt/output.txt' was created (output property 'output'). Task output caching requires exclusive access to output paths to guarantee correctness (i.e. multiple tasks are not allowed to produce output in the same location).
Yup I believe you're right.
I think the problem is that we should be using paths that are per-sourceSet (like build/ktfmt/check/output.txt
)
π Describe the bug
When a project has multiple sourceSets (e.g. main, test) the task caching is not working properly because the task output file changes.
Running multiple format checks together with the --info flag shows this
From a quick look at the code, the issue seems to orginate from the KtfmtCheckTask class. The output value is set to
layout.buildDirectory.file("ktfmt/output.txt")
. If multiple sourcesets exist, they share the output file. Therefore the file changes between tasks and the task is marked as Not-Up-To-Date.β οΈ Current behavior
The checkFormat task is executed every time, even though none of the inputs have changed.
β Expected behavior
Ideally the task would be marked as Up-to-date.
π£ Steps to reproduce
You simply need a repository with two or more sourceSets and execute the ktfmtCheck task twice. If required, I can provide an example repository
Proposed solution
The output file could have a suffix/prefix of the current sourceSet. This can either be provided as additional input or you could specify the output file directly in the KtfmtPluginUtils class.
I think this could already be enough.
π· Screenshots
π± Tech info
If you are fine with this plan, I could draft a PR.