api / org.gradle.process / JavaExecSpec

JavaExecSpec

interface JavaExecSpec : JavaForkOptions, BaseExecSpec

Specifies the options for executing a Java application.

Functions

args

abstract fun args(vararg args: Any): JavaExecSpec
abstract fun args(args: MutableIterable<*>): JavaExecSpec

Adds args for the main class to be executed.

classpath

abstract fun classpath(vararg paths: Any): JavaExecSpec

Adds elements to the classpath for executing the main class.

getArgs

abstract fun getArgs(): MutableList<String>

Returns the arguments passed to the main class to be executed.

getArgumentProviders

abstract fun getArgumentProviders(): MutableList<CommandLineArgumentProvider>

Argument providers for the application.

getClasspath

abstract fun getClasspath(): FileCollection

Returns the classpath for executing the main class.

getMain

abstract fun getMain(): String

Returns the fully qualified name of the Main class to be executed.

setArgs

abstract fun setArgs(args: MutableList<String>): JavaExecSpec
abstract fun setArgs(args: MutableIterable<*>): JavaExecSpec

Sets the args for the main class to be executed.

setClasspath

abstract fun setClasspath(classpath: FileCollection): JavaExecSpec

Sets the classpath for executing the main class.

setMain

abstract fun setMain(main: String): JavaExecSpec

Sets the fully qualified name of the main class to be executed.

Inherited Functions

bootstrapClasspath

abstract fun bootstrapClasspath(vararg classpath: Any): JavaForkOptions

Adds the given values to the end of the bootstrap classpath for the process.

copyTo

abstract fun copyTo(options: JavaForkOptions): JavaForkOptions

Copies these options to the given options.

getAllJvmArgs

abstract fun getAllJvmArgs(): MutableList<String>

Returns the full set of arguments to use to launch the JVM for the process. This includes arguments to define system properties, the minimum/maximum heap size, and the bootstrap classpath.

getBootstrapClasspath

abstract fun getBootstrapClasspath(): FileCollection

Returns the bootstrap classpath to use for the process. The default bootstrap classpath for the JVM is used when this classpath is empty.

getCommandLine

abstract fun getCommandLine(): MutableList<String>

Returns the full command line, including the executable plus its arguments.

getDebug

abstract fun getDebug(): Boolean

Determines whether debugging is enabled for the test process. When enabled — debug = true — the process is started in a suspended state, listening on port 5005. You should disable parallel test execution when debugging and you will need to reattach the debugger occasionally if you use a non-zero value for org.gradle.api.tasks.testing.Test#getForkEvery().

getDefaultCharacterEncoding

abstract fun getDefaultCharacterEncoding(): String

Returns the default character encoding to use.

getEnableAssertions

abstract fun getEnableAssertions(): Boolean

Returns true if assertions are enabled for the process.

getErrorOutput

abstract fun getErrorOutput(): OutputStream

Returns the output stream to consume standard error from the process executing the command. Default to System.err.

getJvmArgs

abstract fun getJvmArgs(): MutableList<String>

Returns the extra arguments to use to launch the JVM for the process. Does not include system properties and the minimum/maximum heap size.

getJvmArgumentProviders

abstract fun getJvmArgumentProviders(): MutableList<CommandLineArgumentProvider>

Command line argument providers for the java process to fork.

getMaxHeapSize

abstract fun getMaxHeapSize(): String

Returns the maximum heap size for the process, if any.

getMinHeapSize

abstract fun getMinHeapSize(): String

Returns the minimum heap size for the process, if any.

getStandardInput

abstract fun getStandardInput(): InputStream

Returns the standard input stream for the process executing the command. The stream is closed after the process completes. Defaults to an empty stream.

getStandardOutput

abstract fun getStandardOutput(): OutputStream

Returns the output stream to consume standard output from the process executing the command. Defaults to System.out.

getSystemProperties

abstract fun getSystemProperties(): MutableMap<String, Any>

Returns the system properties which will be used for the process.

isIgnoreExitValue

abstract fun isIgnoreExitValue(): Boolean

Tells whether a non-zero exit value is ignored, or an exception thrown. Defaults to false.

jvmArgs

abstract fun jvmArgs(arguments: MutableIterable<*>): JavaForkOptions
abstract fun jvmArgs(vararg arguments: Any): JavaForkOptions

Adds some arguments to use to launch the JVM for the process.

setAllJvmArgs

abstract fun setAllJvmArgs(arguments: MutableList<String>): Unit
abstract fun setAllJvmArgs(arguments: MutableIterable<*>): Unit

Sets the full set of arguments to use to launch the JVM for the process. Overwrites any previously set system properties, minimum/maximum heap size, assertions, and bootstrap classpath.

setBootstrapClasspath

abstract fun setBootstrapClasspath(classpath: FileCollection): Unit

Sets the bootstrap classpath to use for the process. Set to an empty classpath to use the default bootstrap classpath for the specified JVM.

setDebug

abstract fun setDebug(enabled: Boolean): Unit

Enable or disable debugging for the process. When enabled, the process is started suspended and listening on port 5005.

setDefaultCharacterEncoding

abstract fun setDefaultCharacterEncoding(defaultCharacterEncoding: String): Unit

Sets the default character encoding to use. Note: Many JVM implementations support the setting of this attribute via system property on startup (namely, the file.encoding property). For JVMs where this is the case, setting the file.encoding property via #setSystemProperties(java.util.Map) or similar will have no effect as this value will be overridden by the value specified by #getDefaultCharacterEncoding().

setEnableAssertions

abstract fun setEnableAssertions(enabled: Boolean): Unit

Enable or disable assertions for the process.

setErrorOutput

abstract fun setErrorOutput(outputStream: OutputStream): BaseExecSpec

Sets the output stream to consume standard error from the process executing the command. The stream is closed after the process completes.

setIgnoreExitValue

abstract fun setIgnoreExitValue(ignoreExitValue: Boolean): BaseExecSpec

Sets whether a non-zero exit value is ignored, or an exception thrown.

setJvmArgs

abstract fun setJvmArgs(arguments: MutableList<String>): Unit
abstract fun setJvmArgs(arguments: MutableIterable<*>): Unit

Sets the extra arguments to use to launch the JVM for the process. System properties and minimum/maximum heap size are updated.

setMaxHeapSize

abstract fun setMaxHeapSize(heapSize: String): Unit

Sets the maximum heap size for the process.

setMinHeapSize

abstract fun setMinHeapSize(heapSize: String): Unit

Sets the minimum heap size for the process.

setStandardInput

abstract fun setStandardInput(inputStream: InputStream): BaseExecSpec

Sets the standard input stream for the process executing the command. The stream is closed after the process completes.

setStandardOutput

abstract fun setStandardOutput(outputStream: OutputStream): BaseExecSpec

Sets the output stream to consume standard output from the process executing the command. The stream is closed after the process completes.

setSystemProperties

abstract fun setSystemProperties(properties: MutableMap<String, *>): Unit

Sets the system properties to use for the process.

systemProperties

abstract fun systemProperties(properties: MutableMap<String, *>): JavaForkOptions

Adds some system properties to use for the process.

systemProperty

abstract fun systemProperty(name: String, value: Any): JavaForkOptions

Adds a system property to use for the process.

Inheritors

JavaExec

open class JavaExec : ConventionTask, JavaExecSpec

Executes a Java application in a child process.

Similar to org.gradle.api.tasks.Exec, but starts a JVM with the given classpath and application class.

 apply plugin: 'java' task runApp(type: JavaExec) { classpath = sourceSets.main.runtimeClasspath main = 'package.Main' // 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