Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Architectural Constraints In Java [closed]

I want to be sure that my project doesn't contain unnecessary dependencies among packages. For example, I want to be sure that the project has layered structure. I.e. model is below everything, business logic depend on model, view dependes on business logic and model. Each of the layers is place in its own package.

Could you recommend any, preferably open source tools which allow me to specify these constraint and check them as a part of continuous integration?

P.S. I know that I can separate the project in separate maven modules. Unfortunately, my real world case is more complex than 3-layered system. If I used maven modules, I would have several dozens of quite small modules.

like image 618
Konstantin Solomatov Avatar asked Nov 19 '12 18:11

Konstantin Solomatov


2 Answers

Although I am not sure if it is possible to enforce a build failure on layer dependency violation, there is at least a tool that can check and visualize these layers: Sonar. You can integrate it with your maven and jenkins builds as well as with eclipse (and maybe other IDEs).

Sonar features a dependency matrix view which visualized the interdependencies of packages.

EDIT: it seems to be possible to configure sonar to force the build to fail triggered by a violation: the build breaker plugin

like image 86
kostja Avatar answered Oct 20 '22 01:10

kostja


This is a very valid question, since lots of projects enforce dependencies through Maven modules, which is a huge waste of productivity and flexibility.

After spending a lot of time researching on this subject I could recommend two tools:

  • Macker (http://innig.net/macker/) it has Maven plugin
  • Classycle (http://classycle.sourceforge.net/) it has to be plugged-in using Ant

Both tools are not evolving much last years, but are working well. Macker has XML-based syntax, but Classycle has neat DSL. Classycle is more high-level specialized tool and has concept of layers. These tools allow you to enforce strict barriers between packages and certain class types. This tools should be configured in build process to fail upon any constraint immediately.

Check the layering example here (http://innig.net/macker/example/layering/src/macker.xml) and here (http://classycle.sourceforge.net/ddf.html#layer).

There is still a niche for a good open source tool, which would hook into compiler and would give you errors while you are in IDE rather than in build tool. Structure101 is much more feature rich, but also heavy and relies on Eclipse plugin.

Update

These is also JQAssistant, which is very powerful, but can take quite some time to learn and setup.

like image 45
Dmitry Buzdin Avatar answered Oct 20 '22 01:10

Dmitry Buzdin