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>

Comment From: sbrannen

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.

Comment From: chicobento

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

Comment From: snicoll

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