How to make sure that Spring Framework artifacts have consistent versions in Maven? It turns out that its very easy to prevent library mismatch errors!
Spring parent dependency
Include “Bill of Materials” to make sure all parts of Spring Framework are in correct versions. This includes all, even transitive dependencies:
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-framework-bom</artifactId> <version>4.3.4.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
Spring project dependency
Now you don’t need to provide version tag anymore for Spring Framework artifacts:
<dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> </dependencies>
Display Maven dependency tree
Let’s check Spring dependencies using Maven:
$> mvn dependency:tree [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building spring 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ java --- [INFO] com.farenda.tutorials.spring:jar:0.0.1-SNAPSHOT [INFO] \- org.springframework:spring-context:jar:4.3.4.RELEASE:compile [INFO] +- org.springframework:spring-aop:jar:4.3.4.RELEASE:compile [INFO] +- org.springframework:spring-beans:jar:4.3.4.RELEASE:compile [INFO] +- org.springframework:spring-core:jar:4.3.4.RELEASE:compile [INFO] | \- commons-logging:commons-logging:jar:1.2:compile [INFO] \- org.springframework:spring-expression:jar:4.3.4.RELEASE:compile [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 3.087 s [INFO] Finished at: 2016-11-22T21:41:49+01:00 [INFO] Final Memory: 13M/150M [INFO] ------------------------------------------------------------------------
References:
- Check out other Spring Framework Tutorials!