api / org.gradle.process / JavaForkOptions

JavaForkOptions

interface JavaForkOptions : ProcessForkOptions

Specifies the options to use to fork a Java process.

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.

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.

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.

getSystemProperties

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

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

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.

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.

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.

Inherited Functions

copyTo

abstract fun copyTo(options: ProcessForkOptions): ProcessForkOptions

Copies these options to the given target options.

environment

abstract fun environment(environmentVariables: MutableMap<String, *>): ProcessForkOptions

Adds some environment variables to the environment for this process.

abstract fun environment(name: String, value: Any): ProcessForkOptions

Adds an environment variable to the environment for this process.

executable

abstract fun executable(executable: Any): ProcessForkOptions

Sets the name of the executable to use.

getEnvironment

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

The environment variables to use for the process. Defaults to the environment of this process.

getExecutable

abstract fun getExecutable(): String

Returns the name of the executable to use.

getWorkingDir

abstract fun getWorkingDir(): File

Returns the working directory for the process. Defaults to the project directory.

setEnvironment

abstract fun setEnvironment(environmentVariables: MutableMap<String, *>): Unit

Sets the environment variable to use for the process.

setExecutable

abstract fun setExecutable(executable: String): Unit
abstract fun setExecutable(executable: Any): Unit

Sets the name of the executable to use.

setWorkingDir

abstract fun setWorkingDir(dir: File): Unit

Sets the working directory for the process.

abstract fun setWorkingDir(dir: Any): Unit

Sets the working directory for the process. The supplied argument is evaluated as per .

workingDir

abstract fun workingDir(dir: Any): ProcessForkOptions

Sets the working directory for the process. The supplied argument is evaluated as per .

Inheritors

JavaExecSpec

interface JavaExecSpec : JavaForkOptions, BaseExecSpec

Specifies the options for executing a Java application.

Test

open class Test : AbstractTestTask, JavaForkOptions, PatternFilterable

Executes JUnit (3.8.x, 4.x or 5.x) or TestNG tests. Test are always run in (one or more) separate JVMs. The sample below shows various configuration options.

 apply plugin: 'java' // adds 'test' task test { // enable TestNG support (default is JUnit) useTestNG() // enable JUnit Platform (a.k.a. JUnit 5) support useJUnitPlatform() // set a system property for the test JVM(s) systemProperty 'some.prop', 'value' // explicitly include or exclude tests include 'org/foo/**' exclude 'org/boo/**' // show standard out and standard error of the test JVM(s) on the console testLogging.showStandardStreams = true // set heap size for the test JVM(s) minHeapSize = "128m" maxHeapSize = "512m" // set JVM arguments for the test JVM(s) jvmArgs '-XX:MaxPermSize=256m' // listen to events in the test execution lifecycle beforeTest { descriptor -> logger.lifecycle("Running test: " + descriptor) } // Fail the 'test' task on the first test failure failFast = true // listen to standard out and standard error of the test JVM(s) onOutput { descriptor, event -> logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message ) } } 

The test 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 someTestTask --debug-jvm