Class FreezingArchRule

java.lang.Object
com.tngtech.archunit.library.freeze.FreezingArchRule
All Implemented Interfaces:
HasDescription, CanOverrideDescription<ArchRule>, ArchRule, CanBeEvaluated

@PublicAPI(usage=ACCESS) public final class FreezingArchRule extends Object implements ArchRule
A decorator around an existing ArchRule that "freezes" the state of all violations on the first call instead of failing the test. This means in particular that the first run of a FreezingArchRule will always pass. Consecutive calls will only fail if "unknown" violations are introduced (read below for further explanations when a violation is "unknown"). Once resolved, initially "known" violations will fail again if they were re-introduced.

You might consider using this class when introducing a new ArchRule to an existing project that causes too many violations to solve at the current time. A typical example is a huge legacy project where a new rule might cause thousands of violations. Even if it is impossible to fix all those violations at the moment, it is typically a good idea to a) make sure no further violations are introduced and b) incrementally fix those violations over time one by one.

FreezingArchRule uses two concepts to support this use case:
  • a ViolationStore to store the result of the current evaluation and retrieve the result of the previous evaluation of this rule.
    The default ViolationStore stores violations in plain text files within the path specified by freeze.store.default.path of "archunit.properties" (default: archunit_store)
    A custom implementation can be provided in two ways. Either programmatically via persistIn(ViolationStore), or by specifying the fully qualified class name within "archunit.properties", e.g.
    freeze.store=com.fully.qualified.MyViolationStore
  • a ViolationLineMatcher to decide which violations are "known", i.e. have already been present in the previous evaluation.
    The default ViolationLineMatcher compares violations ignoring the line number of their source code location and auto-generated numbers of anonymous classes or lambda expressions.
    A custom implementation can be configured in two ways. Again either programmatically via associateViolationLinesVia(ViolationLineMatcher), or within "archunit.properties", e.g.
    freeze.lineMatcher=com.fully.qualified.MyViolationLineMatcher