need to add the Dependencies of spring web jar 3.1.3 and 3.2.2 in the same pom.xml. Does maven support the same jar of different versions?
-
2http://stackoverflow.com/q/4312553/1119381 – Eugene S Mar 15 '16 at 06:51
1 Answers
In addition to this,
Maven does that in a different way. If there are two dependency declarations with different versions, the higher version takes the precedence.
EDIT1 : This statement is for the direct dependency declaration in the same pom. Forcing the required version to use is the strategy here.
Maven uses dependency mediation to resolve the version conflicts.
AFAIK, as the higher versions always have backward compatibility, preferred is to use the higher version.
Unless there is a very strong reason behind adding a specific version, it all goes to designing the modules and their hierarchy.
This gives you complete insight of how to manage the dependencies using modules. This describes the conflict resolution scenarios.
EDIT2:
For the transitive dependencies, yes the nearest definition is the strategy followed. As in example.

- 1
- 1

- 6,671
- 5
- 32
- 56
-
That is not true or not precise. If there are two dependency declarations with different versions the nearest takes precedence. When nearest is equal then higher version takes the precedence. – michaldo Mar 15 '16 at 08:00
-
1@michaldo, Thanks for the point to add, yes, it is for the transitive dependencies to choose between the dependencies defined. As per the OP spec, I marked it as defining the same dependency with lower and higher versions. How ever, edited the answer to include the example for transitive dependencies.But how ever in the same pom, having two dependencies as explicit `
` tag, highest takes the precedence is what I believe, – Vinay Veluri Mar 15 '16 at 08:34 -
1Good. In past was thinking that Maven always choose higher version because it looks natural. So I believe it is important to point that Maven use less natural nearest-win strategy – michaldo Mar 15 '16 at 08:52