Class Architectures.LayeredArchitecture.DependencySettings

java.lang.Object
com.tngtech.archunit.library.Architectures.LayeredArchitecture.DependencySettings
Enclosing class:
Architectures.LayeredArchitecture

@PublicAPI(usage=ACCESS) public static final class Architectures.LayeredArchitecture.DependencySettings extends Object
Defines which dependencies the layered architecture will consider when checking for violations. Which dependencies are considered relevant depends on the context and the way to define the layered architecture (i.e. are the rules defined on incoming or outgoing dependencies).
Each setting has advantages and disadvantages. Considering less dependencies makes the rules more convenient to write and reduces the number of false positives. On the other hand, it will also increase the likelihood to overlook some unexpected corner cases and thus allow some unexpected violations to creep in unnoticed.
  • Method Details

    • consideringAllDependencies

      @PublicAPI(usage=ACCESS) public Architectures.LayeredArchitecture consideringAllDependencies()
      Defines dependency settings that consider all dependencies when checking for violations. With these settings even dependencies to Object can lead to violations of the layered architecture. However, if the rules are only defined on incoming dependencies (e.g. via mayOnlyBeAccessedByLayers(..)) taking all dependencies into account usually works fine and provides a good level of security to detect corner cases (e.g. dependencies like KnownLayer -> SomewhereCompletelyOutsideOfTheLayers -> IllegalTargetForKnownLayer).
      Returns:
      dependency settings to be used when checking for violations of the layered architecture
    • consideringOnlyDependenciesInAnyPackage

      @PublicAPI(usage=ACCESS) public Architectures.LayeredArchitecture consideringOnlyDependenciesInAnyPackage(String packageIdentifier, String... furtherPackageIdentifiers)
      Defines dependency settings that consider only dependencies from/to certain packages, e.g. the app root. All dependencies that either have an origin or a target outside these packages will be ignored. When set to the root package(s) of the application under test this offers a good balance between eliminating false positives (like dependencies to Object) and preventing unexpected corner cases that conceal some existing violations (e.g. dependencies like KnownLayer -> SomewhereCompletelyOutsideOfTheLayers -> IllegalTargetForKnownLayer).
      Parameters:
      packageIdentifier - package identifier defining which origins and targets of dependencies are relevant
      furtherPackageIdentifiers - Additional package identifiers defining relevant packages
      Returns:
      dependency settings to be used when checking for violations of the layered architecture
    • consideringOnlyDependenciesInLayers

      @PublicAPI(usage=ACCESS) public Architectures.LayeredArchitecture consideringOnlyDependenciesInLayers()
      Defines dependency settings that consider only dependencies between the layers. All dependencies that either have an origin or a target outside any defined layer will be ignored. This provides a high level of convenience to eliminate false positives (e.g. dependencies on Object), but also introduces some danger to overlook corner cases that might conceal some unwanted dependencies. Take for example a layered architecture
      
       Controller(..controller..) -> Service(..service..) -> Persistence(..persistence..)
      then these dependency settings would e.g. not detect an unwanted dependency
      
       myapp.service.MyService -> myapp.utils.SomeShadyUtils -> myapp.controller.MyController
      because myapp.utils is not part of any layer of the layered architecture. For a better balance to also detect such cases refer to consideringOnlyDependenciesInAnyPackage(String, String...).
      Returns:
      dependency settings to be used when checking for violations of the layered architecture