How could I add custom annotation @Generator or other annotation to all class in Java
Description
I want to add custom annotation to all classes that is generated by openapi. Something like @Generated so Jacoco can exclude those classes. Currently generator does support adding annotation to model classes but I want to add it all the classes. I do see @javax.annotation.Generated on all classes but the retention policy is SCOPE so jacoco is not able to exclude those classes from the report.
Is there any functionality like this additionalModelTypeAnnotations: '@lombok.Generated' that supports adding annotations to all classes?
I second this. Another use case is adding @SuppressWarnings annotations since the generated classes usually lead to lots of code warnings difficult to deal with in projects with zero warnings policy.
I also think this feature would be extremely useful and valuable.
- The generated code causes a lot of warnings. Add @SuppressWarnings("all") would make these warnings go away. I think there is a strong argument to just also include this annotation, but an option to add this specific annotation or to add custom annotations would also work.
- There would also be value in having the ability to include
@lombok.Generatedon classes. This could be an option to add this specific annotation, or an option to add custom annotations
Any updates on this? We are facing the same issue.
Yep. I'd also be interested in a solution.
For the record, there is a workaround which isn't pretty but does the job: maven-replacer-plugin. In order to add annotations (in this case: suppress warnings) you can proceed as follows:
<execution>
<phase>process-sources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<filesToInclude>${project.build.directory}/generated-sources/**/*.java</filesToInclude>
<replacements>
<replacement>
<!-- First remove existing @SuppressWarnings annotations in order to avoid duplicating them.-->
<token>(@SuppressWarnings|@edu.umd.cs.findbugs.annotations.SuppressFBWarnings).*</token>
<value></value>
</replacement>
<replacement>
<!-- Now insert our new annotations.-->
<!-- Note that we should really have a '^' here, but it does not work, see bug #98 (https://code.google.com/archive/p/maven-replacer-plugin/issues/
98).-->
<token>public (class|enum|interface) </token>
<value>@SuppressWarnings({ your-list-of-suppressions-here })
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings({ your-list-of-suppressions-here })
public $1 </value>
</replacement>
</replacements>
</configuration>
</execution>
I think we all agree that an "official way" to do this would be better, but at least this gets the job done.