Java Exec
Executes a Java application in a child process.
Similar to Exec, but starts a JVM with the given classpath and application class.
plugins {
id 'java'
}
task runApp(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'package.Main'
// arguments to pass to the application
args 'appArg1'
}
// Using and creating an Executable Jar
jar {
manifest {
attributes('Main-Class': 'package.Main')
}
}
task runExecutableJar(type: JavaExec) {
// Executable jars can have only _one_ jar on the classpath.
classpath = files(tasks.jar)
// 'main' does not need to be specified
// arguments to pass to the application
args 'appArg1'
}
The process can be started in debug mode (see getDebug) in an ad-hoc manner by supplying the `--debug-jvm` switch when invoking the build.
gradle someJavaExecTask --debug-jvm
Also, debug configuration can be explicitly set in debugOptions:
task runApp(type: JavaExec) {
...
debugOptions {
enabled = true
port = 5566
server = true
suspend = false
}
}
Functions
Kotlin extension function for org.gradle.api.tasks.JavaExec.environment.
Kotlin extension function for org.gradle.process.ProcessForkOptions.environment.
args
and passes it to setArgs.Kotlin extension function for org.gradle.process.ProcessForkOptions.setEnvironment.
Kotlin extension function for org.gradle.api.tasks.JavaExec.systemProperties.
Kotlin extension function for org.gradle.process.JavaForkOptions.systemProperties.
Returns the extension of the specified type.
Returns the extension of the specified extensionType.
Properties
The extra properties extension in this object's extension container.