Package com.tngtech.archunit.library
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.
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 Summary
Modifier and TypeMethodDescriptionDefinesdependency settings
that consider all dependencies when checking for violations.consideringOnlyDependenciesInAnyPackage
(String packageIdentifier, String... furtherPackageIdentifiers) Definesdependency settings
that consider only dependencies from/to certain packages, e.g.Definesdependency settings
that consider only dependencies between the layers.
-
Method Details
-
consideringAllDependencies
Definesdependency settings
that consider all dependencies when checking for violations. With these settings even dependencies toObject
can lead to violations of the layered architecture. However, if the rules are only defined on incoming dependencies (e.g. viamayOnlyBeAccessedByLayers(..)
) taking all dependencies into account usually works fine and provides a good level of security to detect corner cases (e.g. dependencies likeKnownLayer -> 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) Definesdependency 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 toObject
) and preventing unexpected corner cases that conceal some existing violations (e.g. dependencies likeKnownLayer -> SomewhereCompletelyOutsideOfTheLayers -> IllegalTargetForKnownLayer
).- Parameters:
packageIdentifier
-package identifier
defining which origins and targets of dependencies are relevantfurtherPackageIdentifiers
- Additionalpackage 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()Definesdependency 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 onObject
), but also introduces some danger to overlook corner cases that might conceal some unwanted dependencies. Take for example a layered architecture
then theseController(..controller..) -> Service(..service..) -> Persistence(..persistence..)
dependency settings
would e.g. not detect an unwanted dependency
becausemyapp.service.MyService -> myapp.utils.SomeShadyUtils -> myapp.controller.MyController
myapp.utils
is not part of any layer of the layered architecture. For a better balance to also detect such cases refer toconsideringOnlyDependenciesInAnyPackage(String, String...)
.- Returns:
dependency settings
to be used when checking for violations of the layered architecture
-