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

Adding option to create @Generated annotation on generated code #424

Merged
merged 3 commits into from
Jul 20, 2022

Conversation

yonatang
Copy link
Contributor

Following the request in #420 and discussion in Netflix/dgs-framework#1147, this PR provides an option to generate @Generated annotation over the generated code (both for Java and Kotlin code generators).

The code will detect which @Generated annotation should be used (javax.annotation.Generated for JVM <= 8 or javax.annotation.processing.Generated for JVM >= 9) and will add that for every relevant TypeSpec (classes, data classes, objects, interfaces, enums, etc). The annotation will contain the generation timestamp, and the code generator name will be com.netflix.graphql.dgs.codegen.CodeGen, as the @Generated spec requires

The Java and Kotlin unit tests will use a schema to generate all relevant types, and will verify they: a) have the @Generated annotation; and b) can get compiled properly with the annotation present.

Copy link
Contributor

@srinivasankavitha srinivasankavitha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR contributions!

@yonatang
Copy link
Contributor Author

I'll change to the suggested name, and I can see the linter is angry with me. I'll fix both.

@srinivasankavitha srinivasankavitha merged commit 278b1da into Netflix:master Jul 20, 2022
@yonatang yonatang deleted the generated-annotation branch July 21, 2022 01:13
@bartebor
Copy link

bartebor commented Jul 29, 2022

@yonatang, thanks for picking up my issue :)

As I see a @javax.annotation.processing.Generated annotation is added to source files and this is great.
Unfortunately above anotation has retention SOURCE and thus is dropped by the compiler so coverage checks don't see the annotation.

Could you use some other annotation (@lombok.Generated) or create custom annotation (no external dependencies) with retention RUNTIME or CLASS, so it would be retained in compiled classes?

The problem with java-provided annotation(s) is explained here: jacoco/jacoco#831 (comment)

@yonatang
Copy link
Contributor Author

yonatang commented Aug 9, 2022

Thanks @bartebor, I was surprised to discover the SOURCE retention annotations are not picked by Jacoco. I guess the best approach is to add a custom CLASS retention @Generated annotation, which Jacoco seems to like better.

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

Successfully merging this pull request may close these issues.

3 participants