GH-406 - Improve detection of AOT types generated by Spring.

We now guard the annotation predicate for @Generated behind a classpath check to avoid a NoClassDefFoundError on previous versions of Spring Framework.
This commit is contained in:
Oliver Drotbohm
2024-01-17 08:02:15 +01:00
parent ac9ba52696
commit 48aa0b246a

View File

@@ -67,7 +67,7 @@ public class ApplicationModules implements Iterable<ApplicationModule> {
private static final ImportOption IMPORT_OPTION = new ImportOption.DoNotIncludeTests();
private static final boolean JGRAPHT_PRESENT = ClassUtils.isPresent("org.jgrapht.Graph",
ApplicationModules.class.getClassLoader());
private static final DescribedPredicate<CanBeAnnotated> IS_AOT_TYPE = annotatedWith(Generated.class);
private static final DescribedPredicate<CanBeAnnotated> IS_AOT_TYPE;
private static final DescribedPredicate<HasName> IS_SPRING_CGLIB_PROXY = nameContaining("$$SpringCGLIB$$");
static {
@@ -85,6 +85,14 @@ public class ApplicationModules implements Iterable<ApplicationModule> {
DETECTION_STRATEGY = loadFactories.isEmpty() ? ApplicationModuleDetectionStrategies.DIRECT_SUB_PACKAGES
: loadFactories.get(0);
IS_AOT_TYPE = ClassUtils.isPresent("org.springframework.aot.generate.Generated",
ApplicationModules.class.getClassLoader()) ? getAtGenerated() : DescribedPredicate.alwaysFalse();
}
@Nullable
private static DescribedPredicate<CanBeAnnotated> getAtGenerated() {
return annotatedWith(Generated.class);
}
private final ModulithMetadata metadata;