Gradle caching disabled: Gradle does not know how file was created

This is a link to my code trying to make my gradle tasks cacheable:

My understanding is that the tasks must be marked cacheable (either via annotation or via outputs.cacheIf), and all inputs and outputs must be annotated. The part that I am stuck on right now is gradle seems to think the task’s output directory is not exclusively owned by the task.

Caching disabled for task ‘:generateProto’: Gradle does not know how file
‘build/generated/source/proto/main’ was created (output property ‘$1’). Task output caching requires
exclusive access to output paths to guarantee correctness.

I audited the code and confirm that no other tasks are creating / writing into that directory besides :generateProto, and the directory is already annotated:

  File getOutputDirForCache() {
    File ret = new File(outputBaseDir)
    return ret

Is there a way to get more details on what may be causing this problem?
I have tried this out on Gradle 4.3 and 4.8 and see the same results.

Someone answered my question here:

Turns out, the directory must be totally empty when the task executes, but in my case the function to get the @Input had a side effect of creating directories in the output dir. It looks like the task can only write to its @OutputDirectory during execution.