ArchUnit
ArchUnit copied to clipboard
@SuppressViolation(SomeRule)
If you use ArchUnit just for writing unit tests in your project, you will always fix the issues found by tests or edit the rules to eventually exclude a class from the set of imported classes. However, I'm using ArchUnit via the maven plugin with a selfmade rule library in many projects. In that scenario you will often face exceptional cases (e.g. a generated class using System.out, violating your ArchRule for that). It's then not possible to exclude this violating class in the rule library. This makes using a centrally maintained ruleset basically impossible for more than a single code base.
Therefore ArchUnit needs something like @SuppressWarning
, @SuppressFBWarnings
, etc. which can be applied to the source class instead of editing the ArchRule. This is very similar to using Spotbugs, Checkstyle etc. with a centrally defined ruleset, but allowing exceptions using annotations or comments on the violating class/method/field.
Not entirely what you're asking for, but maybe a workaround: If you freeze your ArchRule then each specific project can control the exceptions.
Just one thing to add, it should also be possible to put adjusted archunit_ignore_patterns.txt
in each project to ignore the violations on a per project basis: https://www.archunit.org/userguide/html/000_Index.html#_ignoring_violations
We can think about the annotation way, the only thing I don't like so much about this is, that it is the first thing that would demand a compile time dependency of production code to ArchUnit. Unfortunately @SuppressWarnings
can definitely not be (ab-)used, since @Retention(SOURCE)
:thinking: