In short. If your Spring Boot project has an ArchUnit rule wrapped in FreezingArchRule, its green colour says exactly one thing: no new violation compared with a baseline file. It does not say the rule runs before a release, it does not say the whole rule runs, and it does not say the text of the rule is still the one that generated the baseline. In this site's backend, on 8 November 2026, I ran the architecture rules: 22 tests executed, 2 red. One of them is the rule "presentation does not depend on infrastructure", which states in its own text that "every NEW violation fails the build" and which today reports 38 new violations on top of the 224 already in the baseline. Another 7 rules, in three test classes, were executed zero times. And the build command used for deployment skips every test. Here you see how to read this picture, with a minimal example you can redo in ten minutes, and which four checks to run on your own project before trusting an architecture test.
Method. Every number on this page comes from a command I ran on 2026-11-08 on this site's repository (Spring Boot 3.4.7, ArchUnit 1.3.0, JDK 21) or from a line of code I read; the Sources section says which. I changed neither the code nor the baseline.
The problem: a green test is a promise, and promises have conditions
An architecture test does a different job from a unit test. A unit test tells you that a function does what it should; an architecture test tells you that the structure of the code is not drifting. That is why it is only worth anything if someone really runs it, every time the structure can change. If it does not run, or runs somewhere nobody looks, you have a test file and no protection.
The typical situation, probably yours too, is this: the project grew before the rule arrived. Introducing it all at once would make hundreds of places fail, so you use freezing: the existing violations are recorded as known debt, and only what is new fails. This is the route suggested by the official ArchUnit guide, designed precisely for projects where violations number in the hundreds or thousands and cannot be fixed at once. It works, but it moves the risk: from the rule to the baseline, and from the baseline to whoever decides when and where the test is run.
How freezing works, in an example you can actually run
To see the mechanism without the noise of a backend with 222 migrations, I built a three-class project: a controller, a repository and a mail sender, split across two packages (demo.presentation and demo.infrastructure). The rule is the backend's: presentation must not depend on infrastructure, wrapped in FreezingArchRule.freeze(...). You verify it with a single Java file and the ArchUnit 1.3.0 and slf4j-api jars.
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.library.freeze.FreezingArchRule;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
public class Check {
public static void main(String[] args) {
var classes = new ClassFileImporter().importPackages("demo");
ArchRule rule = noClasses().that().resideInAPackage("demo.presentation..")
.should().dependOnClassesThat().resideInAPackage("demo.infrastructure..")
.as("i controller non importano infrastructure (rev. 2)");
FreezingArchRule.freeze(rule).check(classes);
System.out.println("REGOLA VERDE");
}
}
Next to it you need an archunit.properties on the classpath. freeze.store.default.path says where the baseline lives: one text file per rule, to be kept under version control. allowStoreCreation is false if you do not write it (so says the ArchUnit guide): with false the baseline cannot be born by itself and the first run fails; with true it is created on the first run. allowStoreUpdate is true if you do not write it, and allows the stored violations to be updated. I set both to true, like this site's backend, because it is the configuration you meet most often. In a moment you will see that of the two switches, one protects less than its name suggests.
freeze.store.default.path=store
freeze.store.default.allowStoreCreation=true
freeze.store.default.allowStoreUpdate=true
The controller starts with a "wrong" dependency, the repository. First run: the baseline does not exist, it is created with the violations found, and the test passes.
Run 1: the baseline is born
$ java -cp "$CP" Check
REGOLA VERDE
The baseline now contains three lines: constructor, field and method call. A single wrong line of code produces several violations, because ArchUnit counts them per point of contact, not per class. Keep that in mind: "38 violations" does not mean 38 classes.
Constructor <demo.presentation.OrderController.<init>()> calls constructor <demo.infrastructure.OrderRepository.<init>()> in (OrderController.java:4)
Field <demo.presentation.OrderController.repo> has type <demo.infrastructure.OrderRepository> in (OrderController.java:0)
Method <demo.presentation.OrderController.get(int)> calls method <demo.infrastructure.OrderRepository.find(int)> in (OrderController.java:5)
Run 2: I add a dependency
In the same controller I add a MailSender field, which lives in infrastructure. The test fails, and the message reports only the two new violations, not the three frozen ones.
$ java -cp "$CP" Check
Exception in thread "main" java.lang.AssertionError: Architecture Violation [Priority: MEDIUM] - Rule 'i controller non importano infrastructure' was violated (2 times):
Constructor <demo.presentation.OrderController.<init>()> calls constructor <demo.infrastructure.MailSender.<init>()> in (OrderController.java:6)
Field <demo.presentation.OrderController.mail> has type <demo.infrastructure.MailSender> in (OrderController.java:0)
Here is the first misunderstanding worth clearing up. The number in brackets, "2 times", is the count of the non-frozen violations, not the total. If you read "violated 38 times" in a frozen test, it means there are 38 violations more than the baseline, while the total may be much higher.
Run 3: I change one word in the rule text
The baseline is keyed by the text you give the rule with .as(...). I keep the code as it was, with the two new violations still in, and change only the text to "... (rev. 2)".
$ java -cp "$CP" Check
REGOLA VERDE
righe nello store, per file:
5 2cf54d63
3 3b89aa37
Green. The two new violations were silently accepted: ArchUnit found no baseline under the new text (in the source of FreezingArchRule.evaluate the first decision is store.contains(delegate): the store is queried per rule, and a rule with a new text does not exist for it yet), created one with the five current violations (the 5-line file) and treated the debt as cleared again. This site's backend knows this trap: above the two frozen rules there is a comment saying not to change the text of .as(...) because it "silently resets the frozen baseline without failing the build". It is a good comment. But it rests on the attention of whoever edits the file: with this configuration no machine checks it.
I expected allowStoreCreation=false to be enough. I tried, and it is not: with that value and the same changed text the run stayed green, because the store already existed and ArchUnit added the new rule inside the existing store. That switch protects against the case where the store is missing altogether (for example a wrong path): a first run with false and no store fails with StoreInitializationFailedException. What blocks the changed text is the other one, allowStoreUpdate=false, redoing run 3 from a valid baseline:
$ grep allowStore cfg/archunit.properties
freeze.store.default.allowStoreCreation=true
freeze.store.default.allowStoreUpdate=false
$ java -cp "$CP" Check
Exception in thread "main" com.tngtech.archunit.library.freeze.StoreUpdateFailedException: Updating frozen violations is disabled (enable by configuration freeze.store.default.allowStoreUpdate=true)
The price is real and you see it in the next run: with allowStoreUpdate=false even fixing a violation fails, because the baseline would have to shrink.
$ # violazione corretta, allowStoreUpdate=false
Exception in thread "main" com.tngtech.archunit.library.freeze.StoreUpdateFailedException: Updating frozen violations is disabled (enable by configuration freeze.store.default.allowStoreUpdate=true)
5 righe
So there is no free configuration. With true you get a baseline that tightens by itself and can be reset by mistake; with false every change to the baseline becomes a deliberate act (the guide shows how to pass the value with -Darchunit.freeze.store.default.allowStoreUpdate=true for a single run), and the diff goes into review. For a project with few eyes on the code, the second choice costs one extra command and makes every change of debt visible.
Run 4: I fix a violation
I remove the MailSender field again. The baseline shrinks by itself, from 5 to 3 lines: this is the behaviour described by the guide ("if violations are fixed, ArchUnit automatically reduces the stored ones"), which in the backend is made explicit with allowStoreUpdate=true.
$ java -cp "$CP" Check
REGOLA VERDE
righe nello store, per file:
3 2cf54d63
3 3b89aa37
What the rules of this site's backend say
The backend has five architecture test classes. I ran them all with a single command, with the JDK 21 the pom requires (the machine's default JDK is 25).
$ export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
$ cd backend && mvn -q -o test -Dtest='*ArchitectureTest' -Dsurefire.failIfNoSpecifiedTests=false
[ERROR] Tests run: 17, Failures: 1, Errors: 0, Skipped: 0 -- in ...projecthub.ProjectHubArchitectureTest
[ERROR] Tests run: 5, Failures: 1, Errors: 0, Skipped: 0 -- in ...architecture.CleanArchitectureTest
[ERROR] Tests run: 22, Failures: 2, Errors: 0, Skipped: 0
Twenty-two tests, two red. The first, ProjectHubArchitectureTest, is a different rule and deserves its own discussion: "PH-ARCH-02" requires every method of the ProjectHub JPA repositories to contain a tenant token in its name (WorkspaceId, OwnerId, Slug or ProjectId), and it flags JpaPhPokerRoomRepository.findActiveRoomsIdleBefore. That method is called by PhHousekeepingScheduler and has a single parameter, a point in time (idleSince): it does not filter by workspace, so it is cross-tenant by construction. I cannot tell you whether the rule should be relaxed with an explicit exception or the method renamed; I can tell you the rule does not know the exception, and that a red test for a known, accepted case is a test people learn to ignore.
The second red is the frozen rule. Its text says "presentation → application → infrastructure: controllers do not import infrastructure. Historical violations frozen in archunit-store (tracked debt, audit 2026-07-07); every NEW violation fails the build" (translated; the original is in Italian). And that is what it does: it fails. The new violations are 38, with this distribution.
$ grep -E "^(Method|Constructor|Field)" CleanArchitectureTest.txt | ... | sort | uniq -c
31 EbookController
2 DatasetExploreController
2 DatasetSearchController
2 sport.SportIntelligenceController
1 PremiumSubscriptionController
The baseline contains 224 violations, spread over 29 classes. To understand where the 38 come from I looked at the git history of the classes involved, and the picture is more nuanced than "someone broke the rule":
SportIntelligenceController,DatasetExploreControllerandDatasetSearchControllerimportMlServiceAuth, which lives ininfrastructure.http. The imports arrived on 30 October 2026 together with the work to authenticate calls to the ml-service. So a security fix introduced an architectural violation, and the rule saw it. The test did its job; what was missing was a release step that ran it.EbookControllerhas 31 new violations. The 30 October commit adds theEbookLanguagesimport, but I cannot attribute all 31 to that commit alone: the file has a longer history and I did not reconstruct it line by line.PremiumSubscriptionControllerhas a single new violation, and it is the most instructive: the controller was already in the baseline (with 15 lines), but the 6 August 2026 commit used a new enum value,RecordResult.RETRYABLE, to make Stripe webhook retries work again. A class that was already frozen failed because of a new constant. The baseline freezes the violation lines, not the class: if you touch a new point of contact, you pay.
That last point is a strength of freezing, not a flaw: the debt cannot grow even inside an already dirty class. But it also means a baseline created on 7 July (the date written at the top of stored.rules) does not remain a faithful snapshot of code that changes every week, if nobody redoes the count.
Why nobody noticed: where the test runs (and where it does not)
The project has no continuous integration pipeline that runs the Java tests: the two workflows in .github/workflows/ (lighthouse-audit.yml and publish-open-data.yml) do not mention Maven, and deployment is manual by decision. The build command documented for the backend, in the deploy runbook as in the pom.xml comment, is mvn package -DskipTests. So, along the path that takes code into production, the architecture test is never run. It exists, and when you run it by hand it tells you the truth; but nothing guarantees that anyone runs it before a release.
This is not a fault to assign, it is a property of the system to know about. A rule run only when someone remembers measures the memory of whoever remembers, not the code. If your delivery is manual like this one, the place to put the check is the same manual step.
Seven rules that do not run
The command ran 22 tests, but the repository has three architecture classes that ran none.
$ sed -n 4p backend/target/surefire-reports/*ArchitectureTest.txt
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 -- in dev.federicocalo.portfolio.knowledgehub.KnowledgeHubArchitectureTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 -- in dev.federicocalo.portfolio.lms.LmsArchitectureTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 -- in dev.federicocalo.portfolio.projecteconomics.ProjectEconomicsArchitectureTest
These three classes use the @AnalyzeClasses and @ArchTest annotations of the archunit-junit5 module. They contain seven rules in all:
$ grep -c "@ArchTest" backend/src/test/java/dev/federicocalo/portfolio/{knowledgehub/KnowledgeHub,lms/Lms,projecteconomics/ProjectEconomics}ArchitectureTest.java
lms/LmsArchitectureTest.java:3
projecteconomics/ProjectEconomicsArchitectureTest.java:1
knowledgehub/KnowledgeHubArchitectureTest.java:3
The reason, according to the Javadoc of CleanArchitectureTest, is that the archunit-junit5 1.3.0 engine is not discovered by Surefire 3.5.3 on JUnit Platform 1.11.4, and the @ArchTest field "silently produces Tests run: 0, a false green that protects nothing". That class works around the problem with ordinary JUnit Jupiter @Test methods. I measured the zero; the cause is the one written in the Javadoc and I did not reproduce it in isolation. I add one thing I read in the sources: the rules of LmsArchitectureTest use .allowEmptyShould(true), so even if they ran they would be green as long as the lms package is empty. Whether the seven rules would pass today I do not know: I have never seen them run.
The symptom is common and worth learning to spot. An architecture test that has never failed is not necessarily a good test. Before trusting it, look at the number of tests executed in the Surefire report, not at the colour.
Three ways to close the account, and the one not to take
Now that you can read the picture, you have three routes for the frozen rule. I did not apply them: the choice belongs to the owner of the code, and depends on what you want the test to mean.
- Fix the 38. For the three controllers that talk to the ml-service the technical route is to move
MlServiceAuthbehind a port in the application layer, so the controller does not import infrastructure. It costs an interface and an adapter for each point. You get the advantage that the debt really shrinks. - Refreeze on purpose. The ArchUnit guide provides for it ("refreeze"): the baseline is rewritten with the current state. It is legitimate if you do it while looking at the 38 and deciding they are accepted, and say so in the commit. It is not if you do it to bring the green back.
- Turn the rule into a threshold. If your real goal is "debt does not grow by more than N", a per-line baseline is the wrong tool; you need a counter with a maximum.
The one not to take is a fourth, the most convenient: changing the text of .as(...). Run 3 above shows that the test turns green without a single violation having been fixed.
Four checks for your project
These checks are the operational extract of everything else. They are independent, and you can do them in any order.
- Does the rule run? Run the architecture tests and read
Tests run:class by class in the Surefire reports. Zero is an alarm, even if the build is green. - Does anyone run it before release? Read the real build command. If it contains
-DskipTests, the test is not a gate, it is an opinion. - Can the baseline change without anyone deciding it? Search for
allowStoreUpdateinarchunit.properties. If it istrue(the default), a changed rule text creates a new baseline and the test stays green; if it isfalse, it fails withStoreUpdateFailedExceptionand forces you to look at the diff. - Does the green match the present? Check the date at the top of
stored.rulesand when the baseline last changed in git (here the last change is from 7 November 2026, one line fewer):git log -3 --format='%h %ad %s' --date=short -- src/test/resources/archunit-store. A baseline far from the current state of the code deserves to be redone consciously.
A note on method to close this part: checks 1 and 2 take ten seconds with grep, and they are the ones that would have exposed the most serious problems here. The cost of knowing is much lower than the cost of not knowing.
What you can do now
You can read a frozen ArchUnit test for what it really says: "zero violations beyond the baseline", and not "architecture respected". You can recognise the number in brackets as the count of new violations. You can reproduce, in a three-class project, the four situations that matter (baseline birth, new violation, changed text, fixed violation), you know which switch protects against which risk, and you know which four checks to run on your own project before trusting it.
Sources
- ArchUnit User Guide, section "Freezing Arch Rules" (8.6) - behaviour of
FreezingArchRule, defaults ofallowStoreCreation(false) andallowStoreUpdate(true), the system properties andfreeze.refreeze; reopened and reread on 2026-11-13 (the online guide reports these defaults). - Source of
FreezingArchRulein the TNG/ArchUnit repository, main branch - theevaluatemethod (store queried per rule,refreezeViolations, removal of obsolete violations); read on 2026-11-13. The current version on Maven Central is 1.5.1 (metadata read on 2026-11-13), while the backend uses 1.3.0: I did not compare the two quoted lines of source with 1.3.0. backend/src/test/java/dev/federicocalo/portfolio/architecture/CleanArchitectureTest.java- text of the two frozen rules, the comment on the.as(...)key, the Javadoc on the undiscovered engine; read on 2026-11-08.backend/src/test/resources/archunit.propertiesandarchunit-store/stored.rules- baseline settings and creation date (7 July 2026); read on 2026-11-08.- Command
mvn -q -o test -Dtest='*ArchitectureTest' -Dsurefire.failIfNoSpecifiedTests=falseunderbackend/with JDK 21, and the filesbackend/target/surefire-reports/*ArchitectureTest.txt- 22 tests, 2 red, 38 new violations, 3 classes at zero tests; run on 2026-11-08. git log -Son the classesEbookController,DatasetSearchController,DatasetExploreController,SportIntelligenceController,PremiumSubscriptionController- arrival dates of the imports (2026-08-06 and 2026-10-30); run on 2026-11-08.docs/01_foundation/04_deploy/11_deploy_manuale.md(§2.5, line 472) andbackend/pom.xml(line 459) - the build commandmvn package -DskipTests; read on 2026-11-08..github/workflows/contains two workflows and neither mentions Maven (grep -ln "mvn\|maven"with no results).- Three-class example: compiled with
javacand run with ArchUnit 1.3.0 and slf4j-api 2.0.17 from the local Maven repository; the outputs above, including the two withallowStoreUpdate=falseand the failure ofallowStoreCreation=falseon a missing store, are the ones printed on 2026-11-08.
Commenti
Caricamento commenti...
Sign in to comment