ElGlurz
ElGlurz

Reputation: 1

ArchUnit: How to check for unwanted dependecies in the signature / API of a class?

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

Answers (1)

nrainer
nrainer

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

Related Questions