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 - @Requestmapping
Spring Boot is the most popular framework of Java for building enterprise-level web applications and back-ends. Spring Boot has a handful of features that support quicker and more efficient web app development. Some of them are Auto-configuration, Embedded Server, opinionated defaults, and Annotatio
6 min read
Spring Boot - Cache Provider
The Spring Framework provides support for transparently adding caching to an application. The Cache provider gives authorization to programmers to configure cache explicitly in an application. It incorporates various cache providers such as EhCache, Redis, Guava, Caffeine, etc. It keeps frequently a
6 min read
Disable @Cacheable in Spring Boot
Caching is an essential feature in modern web applications, providing faster access to frequently used data and reducing the load on databases. In Spring Boot, the @Cacheable annotation is commonly used to cache method results. However, there may be scenarios where you need to disable caching for sp
5 min read
Introduction to Spring Boot
Spring is widely used for creating scalable applications. For web applications, Spring provides Spring MVC, a commonly used module for building robust web applications. The major drawback of traditional Spring projects is that configuration can be time-consuming and overwhelming for new developers.
5 min read
Spring Boot - Spring Data JPA
Spring Data JPA or JPA stands for Java Persistence API, so before looking into that, we must know about ORM (Object Relation Mapping). So Object relation mapping is simply the process of persisting any java object directly into a database table. Usually, the name of the object being persisted become
6 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