Sunday, July 09, 2017

Spring Standalone Application Setup with Gradle

This post is a continuation of the Spring Standalone Application post. In this post I will go over the application setup and the Gradle build file used for building the project. The assumption here is that Gradle is already installed on the machine and ready to use. For instructions on how to install Gradle please go the Gradle installation page.

Gradle Build File: Gradle Application Plugin

The Gradle Application plugin is very useful for creating Standalone applications that can be run using gradle run. By default, the Gradle Application plugin applies the java plugin and Distribution plugin. You can configure the main class and any JVM arguments that you may want to pass to the application.
To pass the main class name, you can use the mainClassName parameter like below

mainClassName = "main.SpringStandaloneTest"

And to pass any JVM arguments to the application, you can use applicationDefaultJvmArgs as shown below

applicationDefaultJvmArgs = ["-Dprop=val"]

And here is the full build.gradle file I used for the spring standalone application