I'd like to enforce a policy in my project, that if something is made public then it must be used from another package. I'd like to enforce this for pretty much everything - classes, interfaces, methods...
methods()
.that()
.arePublic()
.should()
.onlyBeCalled()
.byClassesThat()
.resideOutsideOfPackage(/*...*/);
However, resideOutsideOfPackage requires a specific String packageName whereas, I'd like to use the package name of the currently traversed method's class'.
In this case you need to implement your own
ArchCondition, I have prepared a skeleton that you can adapt to your needs.Or alternatively split the big condition in smaller ones by writing rules like