How to exclude the "target" folder from ArchUnit tests

210 Views Asked by At

I have a test class that contains multiple ArchUnit rules, including the GeneralCodingRules provided by ArchUnit. However, I want to exclude the target folder from being considered during the ArchUnit tests since it's generated by the build process and not part of my source code.

Is there a way to globally exclude the target folder from my ArchUnit test class without having to define a rule for each exclusion manually? I'd like to ensure that ArchUnit doesn't analyze or report violations in the target folder. Any help or guidance on this would be greatly appreciated.

I am Using ArchUnit JUnit 5 - Version 1.1.0

I'm aware that ArchUnit's @AnalyzeClasses annotation allows me to configure the packages for analysis, but I couldn't find a direct way to exclude specific directories like the target folder from the analysis.

1

There are 1 best solutions below

0
Manfred On

You can implement a custom ImportOption to exactly control which classes you want to import. (The linked source code shows some examples, e.g.class DoNotIncludeTests implements ImportOption.)

However, be aware that ArchUnit (currently) only analyzes byte code (i.e. .class files, no .java files). So if you don't want to consider anything in your target folder (I assume that this is from a Maven build, isn't it?), I wonder what you want to consider at all?