Skip to content

Commit e7fa750

Browse files
committed
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.
1 parent d238121 commit e7fa750

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModules.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class ApplicationModules implements Iterable<ApplicationModule> {
6767
private static final ImportOption IMPORT_OPTION = new ImportOption.DoNotIncludeTests();
6868
private static final boolean JGRAPHT_PRESENT = ClassUtils.isPresent("org.jgrapht.Graph",
6969
ApplicationModules.class.getClassLoader());
70-
private static final DescribedPredicate<CanBeAnnotated> IS_AOT_TYPE = annotatedWith(Generated.class);
70+
private static final DescribedPredicate<CanBeAnnotated> IS_AOT_TYPE;
7171
private static final DescribedPredicate<HasName> IS_SPRING_CGLIB_PROXY = nameContaining("$$SpringCGLIB$$");
7272

7373
static {
@@ -85,6 +85,14 @@ public class ApplicationModules implements Iterable<ApplicationModule> {
8585

8686
DETECTION_STRATEGY = loadFactories.isEmpty() ? ApplicationModuleDetectionStrategies.DIRECT_SUB_PACKAGES
8787
: loadFactories.get(0);
88+
89+
IS_AOT_TYPE = ClassUtils.isPresent("org.springframework.aot.generate.Generated",
90+
ApplicationModules.class.getClassLoader()) ? getAtGenerated() : DescribedPredicate.alwaysFalse();
91+
}
92+
93+
@Nullable
94+
private static DescribedPredicate<CanBeAnnotated> getAtGenerated() {
95+
return annotatedWith(Generated.class);
8896
}
8997

9098
private final ModulithMetadata metadata;

0 commit comments

Comments
 (0)