2017-01-25 00:00:00 +0000

The Spring Boot gradle plugin provides the bootRun task that allows a developer to start the application in a “developer mode” without first building a JAR file and then starting this JAR file. Thus, it’s a quick way to test the latest changes you made to the codebase.

Sadly, most applications cannot be started or would not work correctly without specifying a couple configuration parameters. Spring Boot supports such parameters with it’s application.properties file. The parameters in this file are automatically read when the application is started from a JAR and passed to the application.

The bootRun task also allows to define such properties. The common way of doing this is like this in the build.gradle file:

bootRun {
  jvmArgs =

However, if your are working at the codebase together with other developers, each developer may want to test different use cases and needs different configuration values. She would have to edit the build.gradle each time. And each time she checks in changes to the codebase, she has to check if the build.gradle file should really be checked in. Which is not what we want.

The solution to this problem is a specific properties file for each developer’s local environment that is not checked into the VCS. Let’s call it local.application.properties. In this file, put your applications configuration parameters just as you would in a real application.properties file.

To make the bootRun task load these properties, add the following snippet to your build.gradle:

def Properties localBootRunProperties() {
    Properties p = new Properties();
    p.load(new FileInputStream(
      file(project.projectDir).absolutePath + "/local.application.properties"))
    return p;

Then, in your bootRun task, fill the systemProperties attribute as follows:

bootRun {
  doFirst {
    bootRun.systemProperties = localBootRunProperties()

The call to localBootRunProperties() is put into the doFirst closure so that it gets executed only when the task itself is executed. Otherwise event all other tasks would fail with a FileNotFoundException if the properties file is not found instead of only the bootRun task.

Further Reading

Follow me on Twitter for more tips on how to become a better software developer.

Grow as a Software Engineer in Just 5 Minutes a Week

Join more than 3,800 software engineers who get a free weekly email with hacks to become more productive and grow as a software engineer. Also get 50% off my software architecture book, if you want.

Have a look at the previous newsletters to see what's coming.

On This Page

Get Your Hands Dirty on Clean Architecture
Get Your Hands Dirty

149 reviews on Amazon and Goodreads.

Join more than 5,500 readers.

Subscribe to my mailing list to get 50% off.

Follow Reflectoring