xolstice / protobuf-maven-plugin

Maven Plugin that executes the Protocol Buffers (protoc) compiler
https://www.xolstice.org/protobuf-maven-plugin/
Other
242 stars 79 forks source link

Annotate generated code with @Generated #29

Open madrob opened 7 years ago

madrob commented 7 years ago

Annotating java code with @Generated mark would indicate to static analysis tools that it should be skipped.

I think we can do this by passing --java_opt=annotate_code to protoc, although this behaviour is undocumented.

See also google/protobuf#42 and google/protobuf#2513

madrob commented 7 years ago

The argument only works with protoc 3, looks like.

sergei-ivanov commented 7 years ago

Yes, I've just played around with that, and it seems that it's only supported in proto3. I think I'll wait until the option (in whatever form) is officially supported before introducing any changes into the plugin (otherwise I may potentially be forced to support two incompatible implementations).

masih commented 7 years ago

Would it make sense to support specifying custom options to be passed to protoc? I was thinking that way no compatibility will be broken, and it would allow protoc 3 users to specify options like --java_opt=annotate_code.

sergei-ivanov commented 7 years ago

There's scarse (if at all) documentation on the custom protoc command line options. I literally had to go into the source code of protoc to figure out what that option does. If you check out the linked thread, the protobuf team are actively discouraging the use of --java_opt=annotate_code: https://github.com/google/protobuf/issues/42#issuecomment-314512608 I should say, let's wait and see. Hopefully, protobuf team at Google implements that feature properly and makes it a default option, so that no further tweaking is required on the maven side of things.

masih commented 7 years ago

Fair point. I can't help thinking there will be more options like java_opt in the future, and allowing custom options has the potential to avoid this sort of hassle.

As is I find the plugin very useful, thank you for creating it.

trajano commented 4 years ago

Is there a workaround to enable this right now with the present plugin? Also note that the @Generated must be something that the Code Analysis tool can see so far Jacoco can only see it if it is a runtime annotation, so if they use javax.annotation.Generated, it will not be skipped for analysis.

sergei-ivanov commented 4 years ago

With the current snapshot version of the plugin it is possible to pass arbitrary java_opt parameters to protoc. But the older versions do not support that.

trajano commented 4 years ago

Is there any plan to release the snapshot?