Spring Boot – Build Systems

In Spring Boot, choosing a build system is an important task. We recommend Maven or Gradle as they provide a good support for dependency management. Spring does not support well other build systems.

1. Dependency Management

Spring Boot team provides a list of dependencies to support the Spring Boot version for its every release. You do not need to provide a version for dependencies in the build configuration file. Spring Boot automatically configures the dependencies version based on the release. Remember that when you upgrade the Spring Boot version, dependencies also will upgrade automatically.

Note − If you want to specify the version for dependency, you can specify it in your configuration file. However, the Spring Boot team highly recommends that it is not needed to specify the version for dependency.

2. Maven Dependency

For Maven configuration, we should inherit the Spring Boot Starter parent project to manage the Spring Boot Starters dependencies. For this, simply we can inherit the starter parent in our pom.xml file as shown below.

<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>1.5.8.RELEASE</version>
</parent>

We should specify the version number for Spring Boot Parent Starter dependency. Then for other starter dependencies, we do not need to specify the Spring Boot version number. Observe the code given below −

<dependencies>
   <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
   </dependency>
</dependencies>

3. Gradle Dependency

We can import the Spring Boot Starters dependencies directly into build.gradle file. We do not need Spring Boot start Parent dependency like Maven for Gradle. Observe the code given below −

buildscript {
   ext {
      springBootVersion = '1.5.8.RELEASE'
   }
   repositories {
      mavenCentral()
   }
   dependencies {
      classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
   }
}

Similarly, in Gradle, we need not specify the Spring Boot version number for dependencies. Spring Boot automatically configures the dependency based on the version.

dependencies {
   compile('org.springframework.boot:spring-boot-starter-web')
}

Related posts:

Spring Boot - OAuth2 with JWT
Lớp HashMap trong Java
Hướng dẫn Java Design Pattern – MVC
Spring Security Remember Me
Java Program to Implement ConcurrentHashMap API
Join and Split Arrays and Collections in Java
Java – File to Reader
Java Program to Implement TreeMap API
Java Program to Perform Left Rotation on a Binary Search Tree
REST Web service: Upload và Download file với Jersey 2.x
Spring Security Basic Authentication
Copy a List to Another List in Java
Jackson JSON Views
Java Program to Implement a Binary Search Tree using Linked Lists
Converting a Stack Trace to a String in Java
ExecutorService – Waiting for Threads to Finish
Mix plain text and HTML content in a mail
Java Program to Perform Preorder Non-Recursive Traversal of a Given Binary Tree
Remove All Occurrences of a Specific Value from a List
Testing an OAuth Secured API with Spring MVC
Java Program to Check whether Graph is a Bipartite using 2 Color Algorithm
Using a Mutex Object in Java
Add Multiple Items to an Java ArrayList
Java Program to Compute the Volume of a Tetrahedron Using Determinants
A Guide to JUnit 5
Thao tác với tập tin và thư mục trong Java
Java Program to Create a Random Graph Using Random Edge Generation
Java Program to Compare Binary and Sequential Search
Java Program to Implement Gift Wrapping Algorithm in Two Dimensions
Java Program to Find Median of Elements where Elements are Stored in 2 Different Arrays
Arrays.asList vs new ArrayList(Arrays.asList())
Java Program to Implement Unrolled Linked List