EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Spring Tutorial spring boot gradle
Secondary Sidebar
Spring Tutorial
  • Spring Boot
    • What is Spring Boot
    • Spring Boot flyway
    • Spring Boot framework
    • Spring Boot Logback
    • Spring Boot actuator endpoints
    • Spring Boot gRPC
    • Spring Boot jdbctemplate example
    • Spring Boot ehcache
    • Spring Boot Architecture
    • Spring Boot Port
    • Introduction of spring boot
    • Spring Boot ide
    • Spring Boot Netty
    • Spring Boot ORM
    • Spring Boot Versions
    • Spring Boot JUnit
    • Spring Boot Keycloak
    • Spring Boot gradle
    • Spring Boot Lombok
    • Spring Boot autowired
    • Spring Boot bean
    • Spring Boot hibernate
    • Spring Boot integration test
    • Spring Boot jdbc
    • Spring Boot MongoDB
    • Spring Boot postgresql
    • Spring Boot rest
    • Spring Boot swagger
    • Spring Boot thymeleaf
    • Spring Boot Unit Test
    • Spring Boot Webflux
    • Spring Boot webclient
    • Spring Boot kubernetes
    • Spring Boot Properties
    • Spring Boot Validation
    • Spring Boot Feature
    • Spring Boot Application
    • Spring Boot email
    • Spring Boot MVC
    • Spring Boot Exception Handling
    • Spring Boot Starter Parent
    • Spring Boot Docker
    • Spring Boot Logging
    • Spring Boot Query
    • Spring Boot Multiple Data Sources
    • Spring Boot Basic Authentication
    • Spring Boot Test
    • Spring Boot jwt
    • Spring Boot Liquibase
    • Spring Boot Prometheus
    • Spring Boot debug
    • Spring Boot GraalVM
    • Spring Boot Batch
    • Spring Boot controller
    • Spring Boot CLI
    • Spring Boot file upload
    • Spring Boot interceptor
    • Spring Boot Service
    • Spring Boot Configuration
    • Spring Boot Datasource Configuration
    • Spring Boot Annotations
    • Spring Boot Starter We
    • Spring Boot Actuator
    • Spring Boot DevTools
    • Spring Boot Repository
    • Spring Boot Dependencies
    • Spring Boot Path Variable
    • Spring Boot Microservices
    • Spring Boot Run Command
    • Spring Boot application.properties
    • Spring Boot Transaction Management
    • Spring Boot Banner
    • Spring Boot JPA
    • Spring Boot Change Port
    • Spring Boot RestTemplate
    • Spring Boot cors
    • Spring Boot HTTPS
    • Spring Boot OAuth2
    • Spring Boot Profiles
    • Spring Boot Interview Questions
    • Spring Boot filter
    • Spring boot logging level
    • Spring Boot Cache
    • Spring Boot Advantages
    • Spring Boot Scheduler
    • Spring Boot Initializr
    • Spring Boot Maven
    • Spring Boot Admin
    • Spring Boot Tomcat
    • Spring Boot WebSocket
    • Spring Boot Executable Jar
    • Spring Boot CommandLineRunner
    • Spring Boot DataSource
    • Spring Batch Scheduler
    • Spring Batch Example
    • Spring Batch Tasklet
    • Spring Batch Admin
    • Spring Batch
    • Spring Boot Qualifier
    • Spring Boot War
    • Spring Boot Test Configuration
  • Spring
    • What is Spring Framework?
    • Spring Architecture
    • What is Spring Integration?
    • IoC Containers
    • What is AOP?
    • Spring Modules
    • Spring Batch Processing
    • Spring Batch Partitioner
    • Spring Batch Job
    • Spring AOP
    • Spring Expression Language
    • Dependency Injection in Spring
    • Spring Batch Architecture
    • Spring framework Interview Questions
  • Spring Cloud Basics
    • What is Spring Cloud
    • Spring Cloud Contract
    • Spring Cloud Components
    • Spring Cloud Version
    • Spring Cloud Data Flow
    • Spring cloud stream
    • Spring Cloud Dependencies
    • Spring cloud microservices
    • spring cloud gateway
    • Spring Cloud Config
    • Spring Cloud Kubernetes
    • Spring Cloud Sleuth

Related Courses

Spring Boot Certification Course

Spring Framework Course Training

All in One Data Science Course

spring boot gradle

spring boot gradle

Introduction to spring-boot gradle

It is the plugin that was used to provide the support in gradle, this allows us to package the war archive or executable jar file. To run the spring boot application by using gradle and we can also use the dependency management which was provided by the spring boot dependencies. Gradle plugin requires the version of gradle is 7. x, 6.9, and 6.8. Spring boot will automatically apply the plugin of dependency management and also it will configure the spring boot starter parent dependency, gradle provides the same experience as maven.

What is spring-boot gradle?

  • The spring boot will automatically apply at the time of starting or creating the project. The gradle plugin version which was we have to declare in the spring boot application was determining the version of the spring boot starter parent.
  • We need to set the version of the gradle spring-boot plugin with the actual version of spring boot. Once we have applied the spring-boot plugin to our project then this plugin is automatically archived and it will be making the executable jar file.
  • We can configure our project to build the jar or war file. The main class which was we have loading which was we have to specify in the configuration option or we can add the attribute of the main class to the manifest.
  • I suppose we have not specified a plugin that contained the main class then the plugin will searching in the main class of our project.
  • The gradle plugin extends our build script’s DSL with elements from our spring boot plugin’s spring boot settings.
  • Set the appropriate properties of the spring boot plugin is very important. We can set the backup source properties of the spring boot plugin is true or false.
  • After adding development tools to our project it will automatically be monitoring the application changes which were we have made in our project. Also, we can run our application alternatively to reload the classpath of our application.
  • To load the classpath of our application is very important, it will help at the time of development.
  • To build the war file which was executable and deployable using container we need to mark the dependencies of the embedded container.
  • Gradle is used to manage or helps in spring boot dependencies. We can also manage the package and using the package we can run our application by using the build tool of gradle. Gradle is used to manage the dependencies of spring boot.

How to Run spring boot using Gradle?

  • As we know that gradle is used for dependency management which was used in compiling and packaging the application.
  • We can also run our application using gradle tools at the time of development. To run the gradle project we need to follow the below steps are as follows.
  • First, we need to go to the root location of the gradle application where we build. gradle is present.
  • Then execute the below command to run the gradle is as follows.

# gradle bootRun

spring boot gradle output 1

Plugin

  • Spring boot plugin is published in gradle portal. As we know that gradle is a popular tool used to build the application.
  • We have using the gradlew.bat file in windows to run the gradle application.
  • We can also use the gradlew in Linux to run the gradle application which was automatically created at the time of creating the IDE of the gradle application.
  • We also need to add the gradle dependency in the build. gradle file. This file is present in the root directory of our project.
  • To develop the application using the gradle plugin first we need to add this plugin to in build. gradle file.
  • The spring boot task is used to create the executable JAR file. This file is automatically created when we have to apply the java plugin to it.
  • When we have applying the gradle java plugin it will be taking multiple actions like, first to create the task of boot jar which was used to generate the jar file.
  • The second task is to create the task of boot run which was used to run our application directly.
  • The third task is to create the task of disabling the jar.
  • While creating the bootWar task plugin which is used to generate the war file for our application.
  • At the time of creating the gradle war plugin, we have to disable the war task.

Run application using Gradle

  • Create project template using spring initializer –

In the below example we have to create the project template for gradle. We have to create the project name as a spring-boot-gradle.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Group – com.example
Artifact name – spring-boot-gradle
Name – spring-boot- gradle
Description - Project of spring-boot- gradle
Package name - com.example.spring-boot- gradle
Packaging – Jar
Java – 8
Dependencies – spring web.

spring boot gradle output 2

  • After generating the project, extract files and open this project by using the spring tool suite –

We have extracting the project and opening the same using the spring tool suite are as follows.

spring boot gradle output 3

  • After opening the project using the spring tool suite check the project and its files –

spring boot gradle output 4

  • Run the application –

spring boot gradle output 5

Spring boot application Gradle

The below steps show to create a gradle application.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,754 ratings)
  • Configure the build. gradle file –

Code –

dependencies {   // starting of dependency tab.
compile("org.springframework.boot: spring-boot-starter-web")
dependency   // End of dependency tab.
}

output 6

  • Configure application. properties file –

Code –

Server.port = 8080

output 7

  • Create the main class file –

Code –

public class SpringBootApplication {
public static void main /* main method */ (String[] args){
SpringApplication.run (SpringBootApplication.class);
} }

output 8

  • Create controller file –

Code –

public class DemoController {
public String hello(){
return "spring boot";
}  }

output 9

  • Build and run the project –

output 10

Conclusion

We need to set the version of the gradle plugin with the actual version of spring boot. Gradle is the plugin that was used to provide support in gradle. Gradle plugin requires the version of gradle 7. x, 6.9, and 6.8.

Recommended Articles

This is a guide to spring-boot gradle. Here we discuss How to run spring boot using & Gradle along with the codes in detail. You may also have a look at the following articles to learn more –

  1. Spring Boot Logging
  2. Spring Boot cors
  3. Spring Boot Exception Handling
  4. Spring Boot HTTPS
Popular Course in this category
Spring Boot Training Program (2 Courses, 3 Project)
  2 Online Courses |  3 Hands-on Projects |  22+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Spring Framework Training (4 Courses, 6 Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more