bufbuild / buf-gradle-plugin

Gradle plugin for the Buf CLI
Apache License 2.0
46 stars 13 forks source link

Mark outputs of protobuf-gradle-plugin bufbuild setup tasks #190

Open berksean opened 6 months ago

berksean commented 6 months ago

Currently the following tasks used with protobuf-gradle-plugin operation modify the bufbuild build directory, but do not declare any outputs (Referenced via BufPlugin constants):

Most of the time this is fine, but in some situations Gradle's stale output detection will delete the entire bufbuild directory when processing the copyBufConfig task prior to executing the bufBuild task. Example build output with --info

Resolve mutations for :<project>:copyBufConfig (Thread[Execution worker,5,main]) started.
:<project>:copyBufConfig (Thread[Execution worker,5,main]) started.
> Task :<project>:copyBufConfig
Deleting stale output file: <project dir>/build/bufbuild
Caching disabled for task ':<project>:copyBufConfig' because:
  Not worth caching
Task ':<project>:copyBufConfig' is not up-to-date because:
  No history is available.
Resolve mutations for :<project>:bufBuild (Thread[Execution worker,5,main]) started.
:<project>:bufBuild (Thread[Execution worker,5,main]) started.
> Task :<project>:bufBuild FAILED
Caching disabled for task ':<project>:bufBuild' because:
  Caching has not been enabled for the task
Task ':<project>:bufBuild' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
Running buf from <project dir>/build/bufbuild: `buf build --output <project dir>/build/bufbuild/image.json`

When this occurs, the bufBuild task fails with the following error:

Execution failed for task ':proto-util:bufBuild'.
> > arguments: [<snip>/cache/.gradle/caches/modules-2/files-2.1/build.buf/buf/1.17.0/c457961d250281618ad8057e2de721e3d72ebcef/buf-1.17.0-linux-x86_64.exe, build, --output, /<project dir>/build/bufbuild/image.json]
  > exit code: 1
  >    stdout: (empty)
  >    stderr: (below)
  > Failure: no .proto target files found
  > 

I haven't been able to reproduce it locally, as I'm sure the CI configuration is doing something nutty, but this regularly occurs in the CI build. I've been able to fix this by manually setting the outputs for the above tasks to layout.buildDirectory.dir(BUF_BUILD_DIR):

Ideally the tasks would properly specify their specific outputs, and perhaps additionally the dependent tasks would simply depend on the task outputs directly instead of dependsOn relationships to tasks. That would follow Gradle recommended practices more closely, and also give Gradle a bit more insight into the dependency graph.