我有两个单独的包:
mycomp.sales
- Order
- OrderPlaced
mycom.delivery
- Delivery
- OrderPlacedListener (depends on mycomp.sales.OrderPlaced)
我想设置一个规则来检查包mycom.delivery
是否只依赖于OrderPlaced
包中的其他类,而没有其他类mycomp.sales
。
到目前为止,我想出了这个:
JavaClasses importedClasses = new ClassFileImporter().importPackages("mycomp.delivery");
ArchRule rule = classes()
.should().onlyDependOnClassesThat().resideOutsideOfPackages("mycomp.sales..")
.orShould().onlyDependOnClassesThat().areAssignableTo(OrderPlaced.class);
rule.check(importedClasses);
但这在OrderPlacedListener
(依赖于mycomp.sales.OrderPlaced
)上失败了。
这个怎么做?