Spring Boot Gradle Plugin
Last Updated :
09 Apr, 2024
The Spring Boot Gradle plugin provides several Spring Boot-specific features to Gradle, a popular build tool for Java projects. It helps to build and manage the lifecycle of Spring Boot applications. The Spring Boot Gradle plugin enables us to build and manage our Spring Boot applications with the Gradle build tool. This offers so many features, such as :
- Building executable jar or war files.
- Generating a Bill of Materials (BOM) for dependency management.
- Creating a build-info file for version and build metadata.
- Creating native executable images using the Packaging for Containers (PFC) technology.
Prerequisites:
To use the Spring Boot Gradle Plugin, make sure you have the following:
- JDK (Java Development Kit) 8 or later.
- Gradle 4.0 or later.
- Spring Boot 1.5.x or later.
- We must Install the Spring tool (STS).
Gradle Plugin in Spring Boot
1. First, we apply the Spring Boot Plugin to your 'build.gradle' file.
groovy:
plugins {
id 'org.springframework.boot' version '2.5.4'
}
2. We can also apply the Plugin using the legacy plugin application format:
groovy:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.5.4")
}
}
apply plugin: "org.springframework.boot"
3. Dependency Management: To manage dependencies using Spring Boot Plugin, you can use the 'dependencyManagement' section to import the Spring Boot BOM.
groovy:
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:2.5.4")
}
}
dependencies {
implementation "org.springframework.boot:spring-boot-starter-web"
}
4. Building Executable JAR and WAR files: To build an executable JAR or WAR file, we can use the 'bootJar' or bootWar' tasks.
groovy:
bootJar {
mainClassName = 'com.example.demo.Application'
}
5. To build the application with a native image, we can use the 'bootBuildImage' task:
tasks.named("bootBuildImage") {
imageName.set("docker.example.com/library/${project.name}")
}
6. Generating Build-Info Files: Generate a build-info file, you can use the 'bootBuildInfo' task:
springBoot {
buildInfo {
properties {
artifact = 'example-app'
version = '1.2.3'
group = 'com.example'
name = 'Example application'
}
}
}
Step-by-Step Implementation of Gradle Plugin in Spring Boot
Let's create a simple Spring Boot project by using Gradle.
- Open Spring tool STS
- Click on new project select spring starter project

- Create a project name after this select Gradle groovy and click on Next.
- Now, the Spring Boot project is created successfully.

build.gradle: Inside this, we have Gradle plugin dependencies as mentioned below:
plugins {
id 'org.springframework.boot' version '2.5.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:2.5.4")
}
}
dependencies {
implementation "org.springframework.boot:spring-boot-starter-web"
testImplementation "org.springframework.boot:
In this article, we have learnt about Spring Boot Gradle Plugin.
Similar Reads
Spring Boot - Packaging The Spring Framework was created to provide an open-source application framework to feature better infrastructure support for developing Java applications. It is one of the most popular Java Enterprise Edition (Java EE) frameworks, Spring framework helps developers in creating high-performing applic
11 min read
Spring Boot - DevTools Spring Boot provides DevTools, a module designed to ease your development process, it improves the experience of developing applications resulting in optimizing the developer's productivity for building exceptional software.It aims to reduce development time, by intelligently detecting code changes
5 min read
Spring Boot - Auto-configuration Spring Boot is heavily attracting developers toward it because of three main features as follows: Auto-configuration - such as checking for the dependencies, the presence of certain classes in the classpath, the existence of a bean, or the activation of some property.An opinionated approach to confi
5 min read
Spring Boot - Getting Started Spring Boot is a part of the larger Spring Framework ecosystem which is known for its comprehensive programming and configuration model for the modern Java-based enterprise applications. Spring Boot has emerged as a go-to framework for creating REST APIs, microservices, and web applications with les
5 min read
Spring Boot MockMVC Example Automated testing plays a vital role in the software industry. In this article, let us see how to do the testing using MockMvc for a Spring Boot project. To test the web layer, we need MockMvc and by using @AutoConfigureMockMvc, we can write tests that will get injected. SpringBootApplication is an
3 min read
Spring Boot - Admin Client In Sprint Boot, Admin and Client can be implemented so that the client can be registered with the server, and then the server maintains the client's service health and availability, scales up the service, and also measures the representation of the client. Spring Boot Admin ServerThe Admin Server ca
4 min read
Spring Boot - Dependency Management Spring Boot framework is the most popular web development framework. No doubt, it provides an abundance of essential features and a convenient way to handle those features. At the heart of Spring Boot is the 'Dependency Management' feature. Importance of Dependency ManagementCentralized Dependency M
6 min read
Spring Boot - Starter Parent Spring Boot Starter Parent is a starter project that provides the default configuration for spring-based applications. It is added as a parent in the pom.xml file. The spring-boot-starter-parent defines spring-boot-dependencies as its parent. The spring-boot-starter-parent inherits dependency manage
3 min read
Spring Boot - Configuring a Main Class Spring Boot simplifies the process of creating and running Java applications by providing a set of conventions and auto configurations. The main class in the Spring Boot application acts as the entry point where the application starts the execution. It is responsible for bootstrapping the Spring con
4 min read
Multi-Module Project With Spring Boot Multi-Module project with Spring Boot refers to a project structure where multiple modules or subprojects are organized under a single parent project. Each module can represent a distinct component, functionality, or layer of the application, allowing for better organization, maintainability, and co
6 min read