Adoption reference · ArchUnit 1.5.1
Keep progress in the baseline
Version the accepted violation descriptions and review every change to them.
Local configuration
The lab stores these properties in src/test/resources/archunit.properties:
freeze.store.default.path=archunit_store
freeze.store.default.allowStoreCreation=false
freeze.store.default.allowStoreUpdate=true
freeze.refreeze=false
The path is relative to the test JVM's working directory. The lab pins that directory to the Maven
project directory, so running Maven with -f does not move the store. Configure the same
working directory for direct IDE test runs. Keep the store outside target/.
allowStoreUpdate=true permits normal removal of resolved violations. It does not normally
accept a new violation for an already recorded rule. freeze.refreeze=true deliberately
replaces the baseline with current results; keep it off during ordinary enforcement.
Configuration in the official guide.
Introduce one rule
- Run the ordinary rule first. Review its actual violations and whether it expresses the intended policy.
- Wrap it with
FreezingArchRule.freeze. With the intended legacy code checked out, run once with-Darchunit.freeze.store.default.allowStoreCreation=true. - Review and version all store files with the test, including the store index. The lab does not ignore them.
- Run with normal settings. Add a forbidden reference temporarily and prove the build fails.
Keep the final rule description stable. The default text store uses descriptions to identify rules;
renaming a description can create another entry. In ArchUnit 1.5.1, a new description can be recorded in
an existing store while allowStoreCreation=false and allowStoreUpdate=true.
The course's isolated tests verified this behavior against the published implementation.
If you choose an explicit description with as(...), make it explain the constraint.
Stable text reduces accidental churn but does not prove the rule's meaning stayed the same.
Review the rule and its selected scope whenever either changes.
CI verifies a reviewed store
This recommended CI policy forbids both creating and changing the baseline during verification:
mvn test \
-Darchunit.freeze.store.default.allowStoreCreation=false \
-Darchunit.freeze.store.default.allowStoreUpdate=false \
-Darchunit.freeze.refreeze=false
Existing recorded violations still pass. New violations fail. A missing store, newly recorded rule, or change needed to remove a resolved violation also fails because CI cannot write the store.
After fixing debt, run locally with updates allowed, inspect the smaller baseline, and include it with the code fix. CI then sees an already-current store. This extra failure on an unrecorded improvement is the tradeoff for making baseline changes explicit in review.
An alternative is to allow ordinary shrinking in CI and fail the job if the tracked store changes. That requires an extra check and still needs review to distinguish removals from newly accepted entries. The course uses the simpler read-only policy. These are repository workflow choices, not ArchUnit's defaults.
What freezing can miss or misclassify
The matcher compares descriptions and ignores source line numbers plus generated numbering for anonymous classes and lambda expressions. Editing a class name or method signature can make the same architectural debt look new. Conversely, an equivalent description can still match accepted debt after code changes. Freezing therefore means "no newly unmatched reported violations," not a proof that every changed line complies. FreezingArchRule API.
During refactors, inspect the old and new descriptions. Do not use refreezing as a routine way to turn a red test green. Excluding a whole legacy package also excludes its future code, which is a broader exception than accepting the violations currently present.