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

The plugin does not detect proto file was changed when running build for a second time #331

Closed
dapengzhang0 opened this issue Aug 28, 2019 · 8 comments

Comments

@dapengzhang0
Copy link
Member

dapengzhang0 commented Aug 28, 2019

Use the gradle plugin to generate code, then change the proto file, then build again.
As reproduced in https://sponge.corp.google.com/target?id=ff244382-5595-48fd-b556-4b2694aaf5d4&target=grpc%2Fjava%2Fmaster%2Fpresubmit%2Fandroid&searchFor=

@ejona86
Copy link
Collaborator

ejona86 commented Aug 28, 2019

This was for PR grpc/grpc-java#6099. It used pull/6099/merge:pull_branch ref to pull. Looks like the first build was f2ffd26d2d5500395a3c2bbdf28d92a7dd558ec6 and the second build was d507ea72a.

dapengzhang0 added a commit to grpc/grpc-java that referenced this issue Aug 28, 2019
A gradle plugin [issue](google/protobuf-gradle-plugin#331) was seen for #6099. This PR try to workaround it.
@voidzcy
Copy link
Collaborator

voidzcy commented Aug 28, 2019

The issue is because proto files in the first build contains some proto messages that the proto files with the same filenames in the second build do not have. Since message types are generated in separate java files, when you switch to to the second build without a clean, generated java files for messages that only exist in the first build are not deleted, while they still have dependencies on other messages whose re-generated java files are modified, so compiling those "should-have-been-deleted" java files results in symbol not found error.

This only occurs for cases that the first build contains some messages that the second build does not have. Build systems only add/replace output files if necessary but do not delete things from previous build. This is normal. Gradle compiles all the source files in the SourceSet, this is also reasonable for how it works.

I believe it should be the application's responsibility to ensure output directory does not contain unwanted files before each build. grpc/grpc-java#6103 is doing the correct thing and it's not just a workaround.

@ejona86
Copy link
Collaborator

ejona86 commented Aug 28, 2019

In general, Gradle notices when files have been deleted and recompiles. There's basically no change that is "the application's responsibility".

@voidzcy
Copy link
Collaborator

voidzcy commented Aug 28, 2019

Filed #332, which should be done first before we can make changes to always wipe out generated file directories.

@devinrsmith
Copy link

I've ran across this just now (after a large update to our proto files). IMO, this should be the responsibility of the plugin.

Hopefully anybody else in this situation can use a workaround like this for now:

protobuf {
    protoc { artifact = "com.google.protobuf:protoc:${protocVersion}" }
    generateProtoTasks {
      all().each {
        generateProtoTask ->
          // The generateProto task does not seem to properly clean its previously generated outputs.
          // See https://github.com/google/protobuf-gradle-plugin/issues/332
          // See https://github.com/google/protobuf-gradle-plugin/issues/331
          generateProtoTask.doFirst {
            delete generateProtoTask.outputs
          }
      }
    }
  }

@clayburn
Copy link
Contributor

clayburn commented May 5, 2022

Is this still an issue? I couldn't reproduce, although maybe I'm missing a step here.

@ejona86
Copy link
Collaborator

ejona86 commented May 5, 2022

I suspect this still happens. Basically files can be left over from a previous compilation, so if you delete a message in the .proto you might get strange results.

@ejona86
Copy link
Collaborator

ejona86 commented Nov 5, 2022

Duplicate of #33

@ejona86 ejona86 marked this as a duplicate of #33 Nov 5, 2022
@ejona86 ejona86 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 5, 2022
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

No branches or pull requests

5 participants