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

Annotate generated code with @Generated #29

Open
madrob opened this issue Jul 7, 2017 · 8 comments
Open

Annotate generated code with @Generated #29

madrob opened this issue Jul 7, 2017 · 8 comments

Comments

@madrob
Copy link

madrob commented Jul 7, 2017

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 protocolbuffers/protobuf#42 and protocolbuffers/protobuf#2513

@madrob
Copy link
Author

madrob commented Jul 7, 2017

The argument only works with protoc 3, looks like.

@sergei-ivanov
Copy link
Member

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
Copy link

masih commented Sep 4, 2017

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
Copy link
Member

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:
protocolbuffers/protobuf#42 (comment)
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
Copy link

masih commented Sep 12, 2017

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
Copy link

trajano commented Aug 15, 2020

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
Copy link
Member

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
Copy link

trajano commented Aug 16, 2020

Is there any plan to release the snapshot?

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

No branches or pull requests

4 participants