"Packages should never depend on subpackages" rule #921
grimsa
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I took some time trying to implement the following architectural rule: "Packages should never depend on sub-packages" (explained here).
It took a few iterations, but the final solution was pretty simple:
A custom
DescribedPredicate
:and then the rule itself is as simple as:
This produces violation messages like this:
I'd be happy to open a PR that contributes this (or some part of it) to ArchUnit.
I think the potential contributions (in increasing scope order) are:
JavaPackage
should have methods for determining the relation between packages (e.g. is package A a descendant/ancestor of package B?). This would help avoid callingJavaPackage#getAllSubpackages
for each class independencyOnSubpackages
predicate, and it could then become something like this:dependencyOnSubpackages
could be moved toJavaClass.Predicates
incore
ArchCondition
ofArchConditions.have(JavaClass.Predicates.dependencyOnSubpackages()))
could be added toArchConditions
inlang
ArchCondition
could be added to theClassesShould
fluent APIBeta Was this translation helpful? Give feedback.
All reactions