views:

314

answers:

2

Hi: What is the differences between dependencymanagement and dependencies? I have seen the docs at apache maven web site.However I got nothing. It seems that a dependency defined under the DependencyManagement can be used in its child modules without sepcify the version.For example:

A parent project(Pro-par) define a dependency under the dependencyManagement:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8</version>
    </dependency>
 </dependencies>
</dependencyManagement>

Then at the child of Pro-par, I can use the junit :

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
    </dependency>
 </dependencies>

However I wonder if it is necessary to define the junit at the parent pom? Why not define it directly at the needed module?

A: 

It's like you said; dependencyManagementis used to pull all the dependency information into a common POM file, simplifying the references in the child POM file.

It becomes useful when you have multiple attributes that you don't want to retype in under multiple children projects.

Finally, dependencyManagement can be used to define a standard version of an artifact to use across multiple projects.

Pran
A: 

Dependency Management allows to consolidate and centralize the management of dependency versions without adding dependencies which are inherited by all children. This is especially useful when you have a set of projects (i.e. more than one) that inherits a common parent.

Another extremely important use case of dependencyManagement is the control of versions of artifacts used in transitive dependencies. This is hard to explain without an example. Luckily, this is illustrated in the documentation.

Pascal Thivent