tags:

views:

170

answers:

1

We have this constant discussion in our project as to the granularity of our maven modules. We have come to agree that there may be differences in the needs of a framework (like spring) and an in-house application that is always deployed monolithically.

We also agree that it's fairly sensible to hide implementation details of adapters to external systems behind a separate API module, so the implementation classes don't bleed into the classpath of the main implementations. as But that's as far as we go. It's a web project so we have modules like "web", "core" and "adapter(s)". We have multiple backends, but we don't require plugability.

What criteria do you use for modularizing in maven ? Which modules do you make for web projects ?

+4  A: 

In my opinion, the project division should be pretty fine grained, even for "only a webapp".

I would make separate projects for the data access layer interfaces and implementation, business layer interfaces and implementation, and the webapp itself. I would also make atleast one "commons" project for containing code relevant to more than one of the other projects. But this is just the beginning. I would not hesitate to extract a commons-util project for utility classes relevant regardless of the application that is being developed (String, Date, Reflection, etc). I would also make a project for useful utilities when doing testing (commons-test). And that's just the next step ... ;)

If I wrote generally useful code relevant to hibernate, I would put it in a hibernate-utils project. Useful Spring utilities would go in a spring-utils project etc. When doing this, many projects will only contain a single or a few packages, and the packages will commonly contain few classes.

My reasoning for doing this, is that it helps me think about the code I write. Is this REALLY business logic, or is it general String manipulation, Date manipulation, Hibernate specific logic etc? My layers become cleaner, and it becomes harder to get circular dependencies between packages and projects (we don't want those). In addition, it becomes much easier to reuse code in other projects. There will always be other projects...

I have also found that it is easier for new developers to get a hang of the structure, because the projects become smaller and more manageable; it's easier to start coding when you feel you don't have to under stand everything.

As a last advantage to the fine grained approach, build times reduce because you don't have to build everything every time.

Bent André Solheim
Dont you find that the memory requirements for your IDE explode with such a large number of modules ?
krosenvold
Well, actually no, but I am quite generous with the heap size of the process running my IDE. You could be right that fewer modules require less memory, but it has not been an issue so far. 4GB of ram is reasonably priced these days...
Bent André Solheim
How do you manage dependency versions in this structure? I use a similar approach, but find that my model objects are used by almost everything, and it's a hassle to have to bump versions everywhere when internals of the model layer change.
Kris Nuttycombe
You use snapshot versions for all the small modules. But it does use a significant amount of memory in the IDE with all these modules. 500mb to 1gb memory is not uncommon. Can be a bit painful with 32 bit XP and 3gb memory max
krosenvold