GH-408 - Ignore Spring AOT generated types in architecture model.

We now explicitly exclude classes generated by Spring AOT in the architectural model. For technical reasons, they might introduce dependencies to application components considered module internals otherwise. Also, proxies generated do not need to be considered either.
This commit is contained in:
Oliver Drotbohm
2023-12-06 14:17:43 +01:00
parent 5944f0e5ea
commit 4c60cdc705
5 changed files with 65 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ package org.springframework.modulith.core;
import static com.tngtech.archunit.base.DescribedPredicate.*;
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.*;
import static com.tngtech.archunit.core.domain.properties.HasName.Predicates.*;
import static java.util.stream.Collectors.*;
import java.util.*;
@@ -45,6 +46,7 @@ import org.springframework.util.ClassUtils;
import com.tngtech.archunit.base.DescribedPredicate;
import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.domain.properties.HasName;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.core.importer.ImportOption;
import com.tngtech.archunit.lang.EvaluationResult;
@@ -64,6 +66,8 @@ 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<HasName> IS_AOT_TYPE = nameContaining("__")
.or(nameContaining("$$SpringCGLIB$$"));
static {
@@ -98,7 +102,7 @@ public class ApplicationModules implements Iterable<ApplicationModule> {
this.allClasses = new ClassFileImporter() //
.withImportOption(option) //
.importPackages(packages) //
.that(not(ignored));
.that(not(ignored.or(IS_AOT_TYPE)));
Classes classes = Classes.of(allClasses);