otherwise tell us if we should not put dependencies in parent pom but to put them in individual module poms
My suggestion is similar to this. Dependencies in Parent POM is supposed to be mostly used by inherited project. You shouldn't blindly put everything possible dependencies in you parent. It is ruining the dependency management mechanism.
However, personally I usually put every possible dependencies as dependencyManagement
in parent POM instead (Normally when I have a sligntly bigger project, I make it multi-module, and one of the modules is parent for the project). This help to avoid individual module of same project defining different version of same dependency. By doing so, each module (in most case) only declare the group ID and artifact ID of the dependencies it needs. (I hope your reason of putting every dependency in parent is related)
More information about managing dependencies in parent POM
Update:
To answer OP's question in comment:
Thanks for the suggestion. Parent POM can be cleaned up a bit I guess. But what if the unnecessary dependencies are coming from a 3rd party library and we don't really need/want (because of different versions?) all but just a few of them?
That's a totally different story. In some cases we want to control how dependencies are looked up transitively. There are some techniques you would want to know:
When you declare dependencies, you can declare excludes so it excludes some transitive dependencies, like this:
<dependency>
<groupId>foo</groupId>
<artifactId>foo-core</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<groupId>bar</group>
<artifactId>bar-dep</artifactId>
</exclusion>
</exclusions>
</dependency>
One of the beauties of using dependencyManagement
is, if you put the above stuff in parent POM as dependencyManagement, when several modules need to use foo:foo-core
, they simply declare groupId and artifactId, without needs to repeat those lengthy exclusions
Another way is, for example, you still want bar:bar-dep
in the above example, it is just that you need a version different from that looked up transitively, then you can simply declare the correct version you want in your POM, and Maven is going to use the "nearest" version, as described here
Still other tricks of excluding by depending on an empty dependency, as described in comment in question