Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven dependency without version

Recently I've been working on some improvements in a project developed some time ago, and here's what I found. A lot of dependencies in the pom files go without versions specified, and yet they are resolved. The project consists of 1 root module and 2 submodules. The Aggregator pattern is used, meaning there's no dependencyManagement section at all. The upper-project simply aggregates 2 modules and that's all it does. Subprojects don't refer to it as to a parent. They have a different parent. What I can't grasp is that neither subprojects themselves nor their parent(as a matter of fact, it doesn't have dependencyManagement either) specify versions for some of the dependencies. For instance:

<dependency>     <groupId>javax.mail</groupId>     <artifactId>javax.mail-api</artifactId> </dependency> <dependency>     <groupId>com.sun.mail</groupId>     <artifactId>javax.mail</artifactId> </dependency> <dependency>     <groupId>com.sun.mail</groupId>     <artifactId>imap</artifactId> </dependency> <dependency>     <groupId>org.slf4j</groupId>     <artifactId>jcl-over-slf4j</artifactId> </dependency> <dependency>     <groupId>org.slf4j</groupId>     <artifactId>jul-to-slf4j</artifactId> </dependency> <dependency>     <groupId>ch.qos.logback</groupId>     <artifactId>logback-classic</artifactId> </dependency> 

Can someone help me figure this out? Is maven handling versioning with some default strategy? What is that default strategy?

like image 297
yuranos Avatar asked Apr 06 '15 17:04

yuranos


People also ask

What happens if Maven dependency version is not specified?

Each maven dependency defined in the pom must have a version either directly or indirectly for example, through dependencyManagement or parent. That being said, if the version is not given, then the version provided in the dependencyManagement or the parent pom will be used.

What happens if you don't specify a version in Maven?

Maven won't allow any other either. Build will fail if version is not found.

Does Maven override dependency version?

By taking advantage of Maven's nearest definition logic, developers can override the version of a dependency by declaring it on the root pom. xml file.


1 Answers

Ok, I think I'm gonna answer it myself. Of course I took a look at dependency:tree, but all the dependencies that I mentioned were first-level members of the tree. What I failed to notice right away, is that dependencyManagement is not present in the parent, but it is however present in the submodules, and what is more interesting it contains:

        <dependency>             <groupId>io.spring.platform</groupId>             <artifactId>platform-bom</artifactId>             <version>1.0.2.RELEASE</version>             <type>pom</type>             <scope>import</scope>         </dependency> 

I've never used Spring IO Platform before, so this is a totally new concept for me. As it turns out the platform includes quite a few preconfigured dependencies: http://docs.spring.io/platform/docs/current/reference/htmlsingle/#appendix-dependency-versions

like image 164
yuranos Avatar answered Sep 21 '22 05:09

yuranos