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

Allow AOT generated classes to be excluded from code analyzer tools #30824

Closed
chicobento opened this issue Jul 5, 2023 · 3 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Milestone

Comments

@chicobento
Copy link

chicobento commented Jul 5, 2023

Problem

AOT generated classes are being picked-up by code analyzer tools such as jacoco.
Currently, there's no unified naming pattern or annotation markup to differentiate the generated classes from the regular ones, making it difficult to configure the code analyzer tools to skip generated classes.

I could identify the following patterns (not sure if there are others):

  • *__BeanDefinitions
  • *__ApplicationContextInitializer
  • $$SpringCGLIB$$

Possible Solutions

  1. Create a new custom org.springframework.aot.Generated annotation and add to generated classes (lombok approach). Retention should be class to work with jacoco
  2. Add jakarta.annotation.Generated annotation to generated classes (retention is source thus won't work with jacoco)
  3. Provide a custom package name prefix configuration, e.g, original.package.generated allowing to easily configure exclusion patterns

Configuration could be exposed to spring-boot:process-aot maven plugin.

Workaround

Following exclusion patterns seems to work for jacoco-maven-plugin, not sure if it fits all AOT cases:

<excludes>
    <exclude>**/*__*</exclude>
    <exclude>**/*$$SpringCGLIB$$*</exclude>
</excludes>
@chicobento chicobento changed the title Allow AOT generated classes be excluded from code analyzer tools Allow AOT generated classes to be excluded from code analyzer tools Jul 5, 2023
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 5, 2023
@bclozel bclozel transferred this issue from spring-projects/spring-boot Jul 5, 2023
@bclozel bclozel added in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement labels Jul 5, 2023
@sbrannen
Copy link
Member

sbrannen commented Jul 6, 2023

As you mentioned, @jakarta.annotation.Generated is not retained in the .class file, so that's not a good option.

A custom package name prefix is not an option since the generated types very often need to reside in the same package as non-public application types.

Thus, if we decide to address this issue, an annotation with class-file retention seems like the best option to me.

@chicobento
Copy link
Author

chicobento commented Jul 6, 2023

Completely agree 👍 and that's why I put it as the 1st option.

@snicoll
Copy link
Member

snicoll commented Dec 8, 2023

Each generated class is now annotated with org.springframework.aot.generate.Generated so you should be able to configure your tool accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants