Skip to content

Support for checking transitive dependencies #253

@lukfas

Description

@lukfas

ArchUnit supports checking for dependencies between classes using com.tngtech.archunit.lang.conditions.AnyDependencyCondition via com.tngtech.archunit.lang.conditions.ArchConditions.dependOnClassesThat(DescribedPredicate<? super JavaClass>).

However, this Condition does not cover indirect dependencies.

Checking for immediate dependencies ist sufficient in projects where there exists a consistent architectural guideline that specifies for every package / class the allowed dependencies.

When refactoring a large legacy project without such detailed guidelines, one might still pose independence constraints on two (groups of) classes, but defining guidelines for all indirectly referenced classes would be too expensive. In this case, one has to check for the absence of transitive dependencies.

As a Proof of Concept, I have implemented a subclass TransitiveDependenceCondition of ArchCondition. It checks for transitive dependencies from the current class to some target class satisfying a target-condition, without passing through other classes matching some ignore-condition.

When used on about 20.000 classes, a check for transitive independence takes much less than the import of all classes. Hence the transitive dependency check itself is not really expensive.
Although this POC is working in our project, it is still preliminary and not as general as it could be.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions