Reputation: 1
I would like to implement an ArchUnit rule that checks for unwanted dependencies. That's easy to do but I'm only interested in violations that are part of the signature / API of the class. E.g. if the class uses an unwanted dependency in a private field or as method parameter of a private method, that's fine since it's not visible from outside.
I'm struggling with the fluent API. My starting point is:
noClasses().that()
.resideInAnyPackage("..domain..", "..application..")
.should()
.dependOnClassesThat()
.resideInAnyPackage(
"badpackage1..",
"badpackage2..");
How can I refine the above rule to only trigger for non-private language elements of my classes?
Upvotes: 0
Views: 362
Reputation: 2623
You could extract an interface and apply the checks to the interface (classes().that().areInterfaces()
). IDEs provide support for interface extraction.
Upvotes: 0