I'm trying to validate the following dependencies:
In this picture, red relationships are forbidden, green relationships are allowed:
If possible I'd like to add these validations to Layered Architecture.
Thank you.
LayeredArchitecture
considers all dependencies between layers. You cannot forbid inheritance, but allow access – nor vice versa. I recommend to define individual specific rules instead:
@ArchTest
ArchRule adapter_should_not_inherit_from_port = noClasses()
.that().resideInAPackage("….adapter")
.should().beAssignableTo(JavaClass.Predicates.resideInAPackage("….port"));
@ArchTest
ArchRule service_should_not_access_port = noClasses()
.that().resideInAPackage("….service")
.should().accessClassesThat().resideInAPackage("….port");