Is it possible to implement design rules

I’d like to write some design rules that involve several classes / packages. Before I get into this, I’d like to know if this is even possible, or if rules are always bound to a specific class or package?

Such design rules coule be e.g.:

  • cyclic references between classes (I couldn’t find a plugin for this)
  • classes that have several equal attributes or methods, but do not share a common interface
  • Interfaces that are nowhere implemented or abstract classes that have no concrete subclass
  • public attributes or methods that are not used from outside a class (besides reflection)
  • bottleneck classes - i.e. classes that are referenced too many times
  • check of java 9 modules (if provided) in pre java 9 projects

some of them can probably be found somewhere (if so, please give me a link), nevertheless I’d like to implement a lot more.


Welcome :slight_smile:

Do you know Sonargraph ?
This might fulfill some of your requirements.
They provide a Sonarqube Plugin and a free edition.


Hi Gilbert!
Thanks for your answer.

Yes I know Sonargraph and I’ve worked with it (several years ago). I’ve developed rules for Sotograph (sister project of Sonargraph), Checkstyle and others in the past. As far as I know it is not possible to write your own checks for Sonargraph - at least not for the free explorer edition.

Right now I am looking for a one-stop solution that is already used at most of my clients (= sonarqube), which includes or can be expanded with design and architecture checks. So to precise my question:

Can I write sonarqube rules that check the design and/or are there plugins (not relying on external tools) that provide those checks?


You might be interested in these rule templates:

Regarding the specific patterns you’ve mentioned, all of those rule would operate at a level above the individual file, and the Java analyzer isn’t there yet. However, I wouldn’t be shocked if it got there this year.