To use the application plugin, include the following in your build script:
build.gradle
plugins {
id 'application'
}
The only mandatory configuration for the plugin is the specification of the main class (i.e. entry point) of the application.
build.gradle.kts
application {
mainClass = "org.gradle.sample.Main"
}
build.gradle
application {
mainClass = 'org.gradle.sample.Main'
}
You can run the application by executing the
run
task (type:
JavaExec
). This will compile the main source set, and launch a new JVM with its classes (along with all runtime dependencies) as the classpath and using the specified main class. You can launch the application in debug mode with
gradle run --debug-jvm
(see
JavaExec.setDebug(boolean)
).
Since Gradle 4.9, the command line arguments can be passed with
--args
. For example, if you want to launch the application with command line arguments
foo --bar
, you can use
gradle run --args="foo --bar"
(see
JavaExec.setArgsString(java.lang.String)
.
If your application requires a specific set of JVM settings or system properties, you can configure the
applicationDefaultJvmArgs
property. These JVM arguments are applied to the
run
task and also considered in the generated start scripts of your distribution.
If your application’s start scripts should be in a different directory than
bin
, you can configure the
executableDir
property.