Package com.tngtech.archunit.library
Class DependencyRules
java.lang.Object
com.tngtech.archunit.library.DependencyRules
DependencyRules provides a set of general
ArchConditions
and ArchRules
for checking dependencies between classes.
For checking dependencies between classes that belong to different
architectural concepts, see also Architectures
and Slices
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ArchRule
A rule that checks that none of the given classes directly depends on classes from upper packages. -
Method Summary
Modifier and TypeMethodDescriptionstatic ArchCondition<JavaClass>
Returns a condition that matches classes that directly depend on classes from upper packages.
-
Field Details
-
NO_CLASSES_SHOULD_DEPEND_UPPER_PACKAGES
A rule that checks that none of the given classes directly depends on classes from upper packages. For an description what "directly depends" means, seeJavaClass.getDirectDependenciesFromSelf()
.This rule is good practice, because otherwise that might prevent packages on that level from being split into separate artifacts in a clean way in the future.
Example that satisfies the rule:
mycomponent |-- api | |-- interface MyPublicInterface |-- subComponentOne | |-- class MyPublicInterfaceImplOne implements MyPublicInterface |-- subComponentTwo |-- class MyPublicInterfaceImplTwo implements MyPublicInterface
Example that violates the rule:
mycomponent |-- interface MyPublicInterface |-- subComponentOne | |-- class MyPublicInterfaceImplOne implements MyPublicInterface // violation |-- subComponentTwo |-- class MyPublicInterfaceImplTwo implements MyPublicInterface // violation
-
-
Method Details
-
dependOnUpperPackages
Returns a condition that matches classes that directly depend on classes from upper packages. For an description what "directly depend" means, seeJavaClass.getDirectDependenciesFromSelf()
.Example that satisfies the rule:
mycomponent |-- api | |-- interface MyPublicInterface |-- subComponentOne | |-- class MyPublicInterfaceImplOne implements MyPublicInterface |-- subComponentTwo |-- class MyPublicInterfaceImplTwo implements MyPublicInterface
Example that violates the rule:
mycomponent |-- interface MyPublicInterface |-- subComponentOne | |-- class MyPublicInterfaceImplOne implements MyPublicInterface // violation |-- subComponentTwo |-- class MyPublicInterfaceImplTwo implements MyPublicInterface // violation
-