Over a million developers have joined DZone.

Continuous Auto-restart With Spring Boot DevTools and Gradle

DZone's Guide to

Continuous Auto-restart With Spring Boot DevTools and Gradle

Couple Gradle's continuous build feature with the recently-released Spring Boot 1.3's DevTools, and you've got continuous auto-restarting.

· Java Zone
Free Resource

The single app analytics solutions to take your web and mobile apps to the next level.  Try today!  Brought to you in partnership with CA Technologies

With the recent release of Spring Boot 1.3, there is a new dependency in town: Spring Boot DevTools. Which enables us to automatically restart Spring Boot applications if some classes in the class path have changed.

This is quite handy for local development, but still, you need to trigger the build phase to recompile the class. In this case, we can use Gradle's continuous build feature and automatically rebuild our project. Spring Boot DevTools will pick up the changes and restart application.

One way to do this is to add the necessary dependencies to your build.gradle. In this example, the DevTool dependency is added only when we run the bootRun task (devconfiguration). There are other features of DevTool that can be useful during development, and at other times as well. So it's up to you on how you want to organize your project.

buildscript {
    dependencies {
    repositories {

apply plugin: 'java'
apply plugin: 'spring-boot'

repositories {

configurations {

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.13'


bootRun {
    // Use Spring Boot DevTool only when we run Gradle bootRun task
    classpath = sourceSets.main.runtimeClasspath + configurations.dev

After this, we just need to open two terminals:

  1. At the first terminal, start Gradle build as a continuous task: gradle build --continuous
  2. At the second terminal, start the Gradle bootRun task: gradle bootRun

Image title

A working example can be found here.

CA App Experience Analytics, a whole new level of visibility. Learn more. Brought to you in partnership with CA Technologies.

java ,gradle ,spring boot

Published at DZone with permission of Davor Sauer. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}