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

Use Jakarta's @Generated annotation if available #1602

Open
netdpb opened this issue Sep 27, 2023 · 2 comments
Open

Use Jakarta's @Generated annotation if available #1602

netdpb opened this issue Sep 27, 2023 · 2 comments
Labels
Component: common P4 type=enhancement Make an existing feature better

Comments

@netdpb
Copy link
Member

netdpb commented Sep 27, 2023

After javax.annotation.Generated was deprecated in Java 9, AutoValue and other users of GeneratedAnnotations started using the new javax.annotation.processing.Generated replacement if it was available (source version > 8), falling back to the deprecated one otherwise:

if sourceVersion > 8: javax.annotation.processing.Generated
else if in classpath: javax.annotation.Generated

However, it doesn't look for the new EE replacement, which was repackaged jakarta.annotation.Generated. Some users want to switch to that annotation when compiling for Java 8.

We could change GeneratedAnnotations to use the following logic:

if sourceVersion > 8: javax.annotation.processing.Generated
else if in classpath: jakarta.annotation.Generated // new
else if in classpath: javax.annotation.Generated

Alternatively, or in addition, we could add a supported option to each of our processors that lets users specify which @Generated annotation they want the processor to emit, which would let users override that default logic in case they want to emit a different one.

[From a discussion with @suztomo.]

@ronshapiro
Copy link
Contributor

sourceversion > 8 is likely to be true in almost all compilations by this point, right? Especially for people that care about Jakarta.

Perhaps switch the conditions:

if in classpath: jakarta.annotation.Generated // new
else if sourceVersion > 8: javax.annotation.processing.Generated
else if in classpath: javax.annotation.Generated

@netdpb
Copy link
Member Author

netdpb commented Sep 28, 2023

sourceversion > 8 is likely to be true in almost all compilations by this point, right? Especially for people that care about Jakarta.

Unfortunately, that's not the case—which is why this whole thing came up. The Google Cloud libraries are still built with Java 8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: common P4 type=enhancement Make an existing feature better
Projects
None yet
Development

No branches or pull requests

2 participants