Alex Rivera | Logout

Architectural Constraints In Java

Asked 2012-11-19T18:14:35.007
14

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.

Edit
Report

2 Answers

4

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:

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.

answered 2013-02-11T14:09:48.610
1

You can use Checkstyle to implement "customized checks". See it to learn more: http://saturnnetwork.wordpress.com/2012/11/26/ultimate-architecture-enforcement-prevent-code-violations-at-code-commit-time/

I did not try it myself but I think it is not difficult to implement and it's free.

answered 2012-11-27T07:32:08.527

Your Answer