Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint/Format fails with protobuf-gradle-plugin protobuf dependencies #132

Closed
berksean opened this issue May 23, 2023 · 2 comments · Fixed by #133
Closed

Lint/Format fails with protobuf-gradle-plugin protobuf dependencies #132

berksean opened this issue May 23, 2023 · 2 comments · Fixed by #133

Comments

@berksean
Copy link
Contributor

berksean commented May 23, 2023

Buf + protobuf-gradle-plugin seems to work great if all dependencies are of type implementation. The result is that the bufBuild subdirectory of the build directory contains the following:

- build-extracted--include--protos-main/ - Contains proto files from dependencies
- proto/ - symlink to the project's source
- buf.work.yaml - Lists the above two as directories

However, if the project has dependencies of type protobuf (described here), the buf* tasks don't appear to work. In this situation, the bufBuild subdirectory contains the following:

- build-extracted--include--protos-main/ - Contains proto files from "implementation" dependencies
- build-extracted--protos-main/ - Contains proto files from "protobuf" dependencies
- proto/ - symlink to the project's source
- buf.work.yaml - Lists the above three directories, as well as an additional entry for build-extracted--protos-main

The buf tasks fail/appear wrong for what appears to be the following reasons:

  • Duplicate directory in the buf.work.yaml
  • The input directory to the buf command is build-extracted--protos-main, whereas in the implementation only case, the input directory is the project source.

If I go in and delete the duplicate entry for the buf.work.yaml and manually run the command printed when I run the gradle task with the --info task, the wrong protos end up being processed -- those from the dependencies, instead of those from the project source.

The correct behavior would seem to be:

  • buf.work.yaml only contains unique entries
  • the buf command specified the project source directory.

My minor hunch is that protobuf-gradle-plugin includes extracted-protos in project.srcProtoDirs, which is resulting in both of the above behaviors. I think filtering extracted-protos from project.srcProtoDirs would address both issues.

@berksean
Copy link
Contributor Author

berksean commented May 24, 2023

Oddly, I see a test that seems to specifically cover this case -- lint a file with a protobuf dependency and a google dependency with the protobuf-gradle-plugin.

I did some digging and the tests appear to run with protobuf-gradle-plugin version 0.8.19 and pass successfully. Updating to the latest version of 0.9.3 results in a failure. Looks like something changed with how the protobuf plugin behaves.

@andrewparmet andrewparmet linked a pull request Jun 13, 2023 that will close this issue
buildbreaker pushed a commit that referenced this issue Jun 13, 2023
Addresses issue
[132](#132)

Fix buf tasks behavior with more recent versions of the
`protobuf-gradle-plugin`. With version `0.9.3` (and possibly all `0.9.*`
versions), the buf plugin tasks no longer work when `protobuf`
dependencies are used (as described in the issue). This change filters
the hard-coded "extracted" directories from the list of proto source
directories set by the protobuf gradle plugin.

Tested by:
- Updating the test protobuf gradle plugin version to `0.9.3`.
- Verifying tests fail when using protobuf dependencies.
- Adding the extracted directory filter and verifying tests begin to
pass.

---------

Co-authored-by: Sean Chen <[email protected]>
Co-authored-by: Andrew Parmet <[email protected]>
@berksean
Copy link
Contributor Author

Just a note for the future - The fix to this issue will cause future versions of the plugin to stop working with protobuf-gradle-plugin versions < 0.9.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant