Skip to content

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

@berksean

Description

@berksean

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):

  • COPY_BUF_CONFIG_TASK_NAME
  • WRITE_WORKSPACE_YAML_TASK_NAME
  • CREATE_SYM_LINKS_TO_MODULES_TASK_NAME

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions