0

I have a package "parent" which contains packages "parent.child1", "parent.child2" etc.

I wish to enforce that classes in "parent.x" cannot reference classes in "parent.**" (other than in "parent.x" and "parent.x.**").

The first bit is an easy, albeit recursive, Architectural Constraint. The "other than" clause is the tricky bit.

The reason we have this structure in our multi-module maven project is that each "child" is a small and self-contained collection of classes. It is impractical to make each "child" into a maven module. We're talking 5 or 6 classes in each, and it is at developers' discretion to create new "child" packages.

Thanks and regards, Robin.

Robin Roos
  • 100
  • 8

1 Answers1

0

Sorry, but you're going to have to do this the painful way (one rule for each forbidden subpackage) or be very clever with your regex. The parameter values are evaluated as Java regexes, so a negative lookahead ought to work.

EDIT: You could also try a custom rule. XPath's not supported anymore for Java, but you can write custom rules in Java. It's likely that you'd be able to do what you want in a custom rule, but I haven't explored the API's thoroughly enough to know for sure.

Community
  • 1
  • 1
G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76