Maven dependency management 

Joined:
08/13/2009
Posts:
172

January 31, 2012 16:27:39    Last update: January 31, 2012 16:27:39
Because Maven dependencies are transitive, the same artifact may be brought in with different version numbers by multiple other dependencies. For example, the current project may depend on artifact A, which in turn depends on artifact C version 1. It may also have immediate dependency on artifact B, which in turn depends on artifact C version 2.

Maven resolves these version conflicts in the following ways:
  1. Dependency Mediation: If a specific version is not declared in your project POM, Maven resolves the version number by nearest definition, which means it will use the closest dependency in the tree of dependencies for the current project. When dependency depth is the same, it will pick the one that appeared in the POM first.
  2. Dependency Management: dependency versions are specified with the dependencyManagement element. There are three uses of dependencyManagement:
    • Use dependencyManagement in a parent POM so that children POMs can share the same version specification.
    • Use dependencyManagement to control the version of artifacts: dependency management takes precedence over dependency mediation for transitive dependencies. Example:
      <dependencyManagement>
          <dependencies>
      	<dependency>
      	    <groupId>test</groupId>
      	    <artifactId>d</artifactId>
      	    <version>1.0</version>
      	</dependency>
          </dependencies>
      </dependencyManagement>
      

      Version 1.0 of artifact d will be used if d appears in transitive dependendies of the project.
    • Use dependencyManagement to import dependencies. Example:
      <dependencyManagement>
          <dependencies>
      	<dependency>
      	    <groupId>org.richfaces</groupId>
      	    <artifactId>richfaces-bom</artifactId>
      	    <version>4.1.0</version>
      	    <scope>import</scope>
      	    <type>pom</type>
      	</dependency>
          </dependencies>
      </dependencyManagement>
      


Share |
| Comment  | Tags