Class DependencyRules

java.lang.Object
com.tngtech.archunit.library.DependencyRules

@PublicAPI(usage=ACCESS)
public final class DependencyRules
extends java.lang.Object
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

    Fields
    Modifier and Type Field Description
    static ArchRule NO_CLASSES_SHOULD_DEPEND_UPPER_PACKAGES
    A rule that checks that none of the given classes directly depends on classes from upper packages.
  • Method Summary

    Modifier and Type Method Description
    static ArchCondition<JavaClass> dependOnUpperPackages()
    Returns a condition that matches classes that directly depend on classes from upper packages.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NO_CLASSES_SHOULD_DEPEND_UPPER_PACKAGES

      @PublicAPI(usage=ACCESS) public static final ArchRule 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, see JavaClass.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

      @PublicAPI(usage=ACCESS) public static ArchCondition<JavaClass> dependOnUpperPackages()
      Returns a condition that matches classes that directly depend on classes from upper packages. For an description what "directly depend" means, see JavaClass.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