Chapter 32. The Application Plugin

The Gradle application plugin extends the language plugins with common application related tasks. It allows running and bundling applications for the jvm.

32.1. Usage

To use the application plugin, include in your build script:

Example 32.1. Using the application plugin

build.gradle

apply plugin:'application'

To define the main-class for the application you have to set the mainClassName property as shown below

Example 32.2. Configure the application main class

build.gradle

mainClassName = "org.gradle.sample.Main"

Then, you can run the application by running gradle run. Gradle will take care of building the application classes, along with their runtime dependencies, and starting the application with the correct classpath.

The plugin can also build a distribution for your application. The distribution will package up the runtime dependencies of the application along with some OS specific start scripts. You can run gradle install to create an image of the application in build/install/projectName. You can run gradle distZip to create a ZIP containing the distribution.

32.2. Tasks

The Application plugin adds the following tasks to the project.

Table 32.1. Application plugin - tasks

Task name Depends on Type Description
run classes JavaExec Starts the application.
startScripts jar CreateStartScripts Creates OS specific scripts to run the project as a JVM application.
install jar, startScripts Sync Installs the application into a specified directory.
distZip jar, startScripts Zip Creates a full distribution ZIP archive including runtime libraries and OS specific scripts.

32.3. Convention properties

Table 32.2. Application plugin - directory properties

Property name Type Default value Description
mainClassName String - The fully qualified name of the main class of the application.
installDirPath String build/install The path the application should be installed into.

These properties are provided by a ApplicationPluginConvention convention object.