Forked JVM-based Execution
It is possibly to simplify the execution of applications on forked JVMs. Typical cases are running specific JVM-based tools or scripts of a JVM-based scripting language such as JRuby.
Execution specifications
Execution specifications are used for configuring the necessary details for running an external process.
-
AbstractJvmExecSpec is the core class to extend in order to implement JVM-based execution specifications.
-
AbstractJvmExecTask is the core class to extend in order to implement JVM-based execution tasks.
-
AbstractJvmScriptExecSpec is the core class to extend in order to implement JVM-based script specifications.
-
AbstractJvmScriptExecTask is the core class to extend in order to implement JVM-based script tasks.
Configuration
Assuming that you have a task type myJvmTask
that is of a task type that extends AbstractJvmExecTask
you can configure all of the relevant settings as follows:
myJvmTask {
jvm { (1)
}
runnerSpec { (2)
}
entrypoint { (3)
}
process { (4)
}
}
1 | Configures all of the JVM fork options.
It is of type JavaForkOptionsWithEnvProvider and similar to JavaForkOptions , but with the addition of environment variable providers. |
2 | Configures the command-line arguments for executing the class.
This is not the JVM arguments, which need to be configured in jvm instead.
It is of type CmdlineArgumentSpec and similar in nature to the args kind of methods in an ExecSpec . |
3 | Configures the main class and the classpath for the execution.
It is of type JvmEntryPoint and have similar methods to mainClass and classpath that are in `JavaExecSpec. |
4 | Configures the actual execution of the process such as setting the streams. It is of type ProcessExecutionSpec |
In addition to the above, a script task includes a script
configuration block
myJvmTask {
script { (1)
name = 'install' (2)
path = '/path/to/script' (3)
}
}
1 | Configures the script name or path as well as any arguments. It is of type JvmScript. |
2 | It is possible to just specify the name of the script. In this case is up to the specific implementation on how to resolve its location. |
3 | It is also possible to specify a path instead of a script name. If both a name and a path is specified, the name takes preference. |
Configuring the post-process
When the execution method is JAVA_EXEC
, additional configuration can be done to handle the post process actions.
process {
ignoreExitValue = true (1)
output { (2)
capture() (3)
captureAndForward() (4)
captureTo( project.provider { -> file('build/this-output.txt') }) (5)
forward() (6)
noOutput() (7)
}
errorOutput { (8)
capture()
captureAndForward()
captureTo( project.provider { -> file('build/this-output.txt') })
forward()
noOutput()
}
afterExecute { (9)
}
}
1 | Whether to ignore the exit value. |
2 | Configure the standard output. |
3 | Capture the output. |
4 | Capture the output and forward the output to console. |
5 | Write the output to the file. |
6 | Forward the output to console. |
7 | Do not produce any output. |
8 | Configure the error output. |
9 | Add one of more closures/actions to process output.
This is called when the output or error output is captured.
It is passed a ExecOutput instance. |