Here is the current structure of my project (dependencies in POM)
- commons
- generator
-> dependencies: commons
- database
-> dependencies: commons, generator
- statemachine
-> dependencies: commons, database
- server
-> dependencies: commons, statemachine, database, generator
It’s obvious which depends on which. But there is the redundancy I don’t like. If I changed one version, I would have to change it everywhere.
So the better (for me) solution may be this
- commons
- generator
-> commons
- database
-> generator
- statemachine
-> database
- server
-> statemachine
This is much more simple. On the other hand, you can’t see the real structure, you have to use effective POM (if you have this option in IDE).
So my question is: which approach is better and why? Or is there any better way to do this?
In my opinion you should declare those dependencies you need directly, whenever you make use of code or API of e.g. “commons” you should have this dependency in your POM. Otherwise when a transitive dependency you rely on will be removed, you’ll have several problems for already released versions.
The version problems is “solved” by dependency mediation. I hope this helps.