google / google/auto

Use Jakarta's @Generated annotation if available

Open
#1,602 2 comments 0 reactions 0 assignees View on GitHub
Component: common P4 type=enhancement
Dominant language
Java
Stars
10.6k
Forks
1.2k
Avg merge
6h 32m
Merged PRs (30d)
13

Description

After `javax.annotation.Generated` was deprecated in Java 9, AutoValue and other users of [`GeneratedAnnotations`](https://github.com/google/auto/blob/main/common/src/main/java/com/google/auto/common/GeneratedAnnotations.java) 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`](https://jakarta.ee/specifications/annotations/2.0/apidocs/jakarta.annotation/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.]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.