08 July 2014

Out of the box, Spring Boot ships with a Gradle plugin that supports running your application, as well as building an executable JAR or WAR file. The plugin extends off the stock Gradle JavaExec Task, which means that you can use any of the task’s configuration properties to customize how your application runs when launching it via Gradle (e.g. ./gradlew run). For instance, if you would like to set some system properties, environment variables and/or other any other support JVM properties/arguments, you simply need to define an additional run configuration block in your build.gradle build script:

build.gradle
apply plugin: 'java'
apply plugin: 'spring-boot'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath('org.springframework.boot:spring-boot-gradle-plugin:1.1.4.RELEASE')
    }
}

run {
    environment = ['ENV' : 'dev']
    maxHeapSize = '512M'
    systemProperties = ['serverPort':'8085']
}

springBoot {
    mainClass = 'com.test.Application'
}

repositories {
    mavenCentral()
}

dependencies {
    ...
}

For a complete list of the properties of the JavaExec Task that can be set, see the Properties of the JavaExec Task Gradle Documentation.

comments powered by Disqus