Reputation: 35901
In Maven you can override the version number of a transitive dependency by an entry in dependencyManagement because dependencyManagement takes precedence over transitive dependency definitions.
But what about dependencyManagement definitions in the poms of (transitive) dependencies? Are they considered at all? If so, what do they override, how are they overridden?
Upvotes: 15
Views: 1510
Reputation: 4857
Dependency management is implied to be transitive. There doesn't need to be a special rule for this, but rather it's a consequence of the already mentioned rules: Transitive Dependencies.
Consider this example structure:
A
- dependency
D
- transitive dependencyB
- dependency
D
- transitive dependencyWhen A
or B
are built, their corresponding dependencyManagement
section is checked to pick version for D
, if it's not explicitly specified. Here's the important part: exactly the same process is used when A
or B
are used as dependencies to determine which version of D
they depend on. Consequently, they do not affect each other in any way.
This could result, for example, in A
depending on D:1.0
, and B
depending on D:1.1
, their dependencyManagement
sections have already been applied at this point to determine this and will not be taken into account anymore. With this information as input, dependency mediation rules are applied to pick just one version of D
for your module.
Dependency mediation rules are also described in the linked page. But in a nutshell, the nearest definition wins and ties are broken based on order. Naturally, definitions in your module itself are always the nearest.
Now let's say your module is used as a dependency. Your project could depend on D:1.2
based on all the rules above due to a definition in your dependencyManagement
section, but that's where the scope of your dependencyManagement
ends.
(Note that import
scope is an exception as it behaves completely differently from the other scopes.)
Upvotes: 2
Reputation: 1084
dependencyManagement definitions in the poms of transitive dependencies are considered as long as they are not been overridden in the dependencyManagement of your project or a closer dependency (in the tree of dependencies).
in another words,
Dependency mediation: the rule is easy
"nearest definition" which means that it will use the version of the closest dependency to your project in the tree of dependencies.
if two dependency versions are at the same depth in the dependency tree, the first declaration wins (declaration order).
for more details see Transitive Dependency
hope this helps.
Upvotes: 0