From 48aa0b246a7f9e8d0a0e6c6631d88bf941739fa3 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Wed, 17 Jan 2024 08:02:15 +0100 Subject: [PATCH] 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. --- .../modulith/core/ApplicationModules.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModules.java b/spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModules.java index ca9758ce..c3e11919 100644 --- a/spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModules.java +++ b/spring-modulith-core/src/main/java/org/springframework/modulith/core/ApplicationModules.java @@ -67,7 +67,7 @@ public class ApplicationModules implements Iterable { 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 IS_AOT_TYPE = annotatedWith(Generated.class); + private static final DescribedPredicate IS_AOT_TYPE; private static final DescribedPredicate IS_SPRING_CGLIB_PROXY = nameContaining("$$SpringCGLIB$$"); static { @@ -85,6 +85,14 @@ public class ApplicationModules implements Iterable { 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 getAtGenerated() { + return annotatedWith(Generated.class); } private final ModulithMetadata metadata;