Class JavaExec
java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
org.gradle.api.internal.ConventionTask
org.gradle.api.tasks.JavaExec
- All Implemented Interfaces:
Comparable<Task>, org.gradle.api.internal.DynamicObjectAware, org.gradle.api.internal.IConventionAware, org.gradle.api.internal.TaskInternal, ExtensionAware, Task, BaseExecSpec, JavaExecSpec, JavaForkOptions, ProcessForkOptions, org.gradle.util.Configurable<Task>
- Direct Known Subclasses:
RhinoShellExec
Executes a Java application in a child process.
Similar to 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
-
Nested Class Summary
Nested classes/interfaces inherited from interface Task
Task.Namer -
Field Summary
Fields inherited from interface Task
TASK_ACTION, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds args for the main class to be executed.Adds args for the main class to be executed.bootstrapClasspath(Object... classpath) Adds the given values to the end of the bootstrap classpath for the process.Adds elements to the classpath for executing the main class.copyTo(JavaForkOptions options) Copies these options to the given options.copyTo(ProcessForkOptions target) Copies these options to the given target options.environment(String name, Object value) Adds an environment variable to the environment for this process.environment(Map<String, ?> environmentVariables) Adds some environment variables to the environment for this process.voidexec()executable(Object executable) Sets the name of the executable to use.Returns the full set of arguments to use to launch the JVM for the process.getArgs()Returns the arguments passed to the main class to be executed.Returns the bootstrap classpath to use for the process.Returns the classpath for executing the main class.Returns the full command line, including the executable plus its arguments.booleangetDebug()Returns true if debugging is enabled for the process.Returns the default character encoding to use.booleanReturns true if assertions are enabled for the process.The environment variables to use for the process.Returns the output stream to consume standard error from the process executing the command.protected org.gradle.process.internal.ExecActionFactoryReturns the name of the executable to use.Returns the extra arguments to use to launch the JVM for the process.getMain()Returns the fully qualified name of the Main class to be executed.Returns the maximum heap size for the process, if any.Returns the minimum heap size for the process, if any.Returns the standard input stream for the process executing the command.Returns the output stream to consume standard output from the process executing the command.Returns the system properties which will be used for the process.Returns the working directory for the process.booleanTells whether a non-zero exit value is ignored, or an exception thrown.Adds some arguments to use to launch the JVM for the process.Adds some arguments to use to launch the JVM for the process.voidsetAllJvmArgs(Iterable<?> arguments) Sets the full set of arguments to use to launch the JVM for the process.voidsetAllJvmArgs(List<String> arguments) Sets the full set of arguments to use to launch the JVM for the process.Sets the args for the main class to be executed.Sets the args for the main class to be executed.voidsetBootstrapClasspath(FileCollection classpath) Sets the bootstrap classpath to use for the process.setClasspath(FileCollection classpath) Sets the classpath for executing the main class.voidsetDebug(boolean enabled) Enable or disable debugging for the process.voidsetDefaultCharacterEncoding(String defaultCharacterEncoding) Sets the default character encoding to use.voidsetEnableAssertions(boolean enabled) Enable or disable assertions for the process.voidsetEnvironment(Map<String, ?> environmentVariables) Sets the environment variable to use for the process.setErrorOutput(OutputStream outputStream) Sets the output stream to consume standard error from the process executing the command.voidsetExecutable(Object executable) Sets the name of the executable to use.voidsetExecutable(String executable) Sets the name of the executable to use.setIgnoreExitValue(boolean ignoreExitValue) Sets whether a non-zero exit value is ignored, or an exception thrown.voidsetJvmArgs(Iterable<?> arguments) Sets the extra arguments to use to launch the JVM for the process.voidsetJvmArgs(List<String> arguments) Sets the extra arguments to use to launch the JVM for the process.Sets the fully qualified name of the main class to be executed.voidsetMaxHeapSize(String heapSize) Sets the maximum heap size for the process.voidsetMinHeapSize(String heapSize) Sets the minimum heap size for the process.setStandardInput(InputStream inputStream) Sets the standard input stream for the process executing the command.setStandardOutput(OutputStream outputStream) Sets the output stream to consume standard output from the process executing the command.voidsetSystemProperties(Map<String, ?> properties) Sets the system properties to use for the process.voidsetWorkingDir(File dir) Sets the working directory for the process.voidsetWorkingDir(Object dir) Sets the working directory for the process.systemProperties(Map<String, ?> properties) Adds some system properties to use for the process.systemProperty(String name, Object value) Adds a system property to use for the process.workingDir(Object dir) Sets the working directory for the process.Methods inherited from class org.gradle.api.internal.ConventionTask
conventionMapping, conventionMapping, getConventionMappingMethods inherited from class DefaultTask
newInputDirectory, newInputFile, newOutputDirectory, newOutputFileMethods inherited from class org.gradle.api.internal.AbstractTask
addValidator, appendParallelSafeAction, compareTo, configure, deleteAllActions, dependsOn, dependsOnTaskDidWork, doFirst, doFirst, doFirst, doLast, doLast, doLast, execute, finalizedBy, getActions, getAnt, getAsDynamicObject, getConvention, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExecuter, getExtensions, getFinalizedBy, getGroup, getIdentityPath, getImpliesSubProjects, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOnlyIf, getOutputs, getPath, getProject, getServices, getShouldRunAfter, getStandardOutputCapture, getState, getTaskActions, getTaskDependencies, getTemporaryDir, getTemporaryDirFactory, getValidators, hasProperty, injectIntoNewInstance, isEnabled, isHasCustomActions, leftShift, mustRunAfter, onlyIf, onlyIf, prependParallelSafeAction, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setExecuter, setFinalizedBy, setGroup, setImpliesSubProjects, setMustRunAfter, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, toString
-
Constructor Details
-
JavaExec
public JavaExec()
-
-
Method Details
-
getExecActionFactory
@Inject protected org.gradle.process.internal.ExecActionFactory getExecActionFactory() -
exec
public void exec() -
getAllJvmArgs
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.- Specified by:
getAllJvmArgsin interfaceJavaForkOptions- Returns:
- The arguments. Returns an empty list if there are no arguments.
-
setAllJvmArgs
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.- Specified by:
setAllJvmArgsin interfaceJavaForkOptions- Parameters:
arguments- The arguments. Must not be null.
-
setAllJvmArgs
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.- Specified by:
setAllJvmArgsin interfaceJavaForkOptions- Parameters:
arguments- The arguments. Must not be null.
-
getJvmArgs
Returns the extra arguments to use to launch the JVM for the process. Does not include system properties and the minimum/maximum heap size.- Specified by:
getJvmArgsin interfaceJavaForkOptions- Returns:
- The arguments. Returns an empty list if there are no arguments.
-
setJvmArgs
Sets the extra arguments to use to launch the JVM for the process. System properties and minimum/maximum heap size are updated.- Specified by:
setJvmArgsin interfaceJavaForkOptions- Parameters:
arguments- The arguments. Must not be null.
-
setJvmArgs
Sets the extra arguments to use to launch the JVM for the process. System properties and minimum/maximum heap size are updated.- Specified by:
setJvmArgsin interfaceJavaForkOptions- Parameters:
arguments- The arguments. Must not be null.
-
jvmArgs
Adds some arguments to use to launch the JVM for the process.- Specified by:
jvmArgsin interfaceJavaForkOptions- Parameters:
arguments- The arguments. Must not be null.- Returns:
- this
-
jvmArgs
Adds some arguments to use to launch the JVM for the process.- Specified by:
jvmArgsin interfaceJavaForkOptions- Parameters:
arguments- The arguments.- Returns:
- this
-
getSystemProperties
Returns the system properties which will be used for the process.- Specified by:
getSystemPropertiesin interfaceJavaForkOptions- Returns:
- The system properties. Returns an empty map when there are no system properties.
-
setSystemProperties
Sets the system properties to use for the process.- Specified by:
setSystemPropertiesin interfaceJavaForkOptions- Parameters:
properties- The system properties. Must not be null.
-
systemProperties
Adds some system properties to use for the process.- Specified by:
systemPropertiesin interfaceJavaForkOptions- Parameters:
properties- The system properties. Must not be null.- Returns:
- this
-
systemProperty
Adds a system property to use for the process.- Specified by:
systemPropertyin interfaceJavaForkOptions- Parameters:
name- The name of the propertyvalue- The value for the property. May be null.- Returns:
- this
-
getBootstrapClasspath
Returns the bootstrap classpath to use for the process. The default bootstrap classpath for the JVM is used when this classpath is empty.- Specified by:
getBootstrapClasspathin interfaceJavaForkOptions- Returns:
- The bootstrap classpath. Never returns null.
-
setBootstrapClasspath
Sets the bootstrap classpath to use for the process. Set to an empty classpath to use the default bootstrap classpath for the specified JVM.- Specified by:
setBootstrapClasspathin interfaceJavaForkOptions- Parameters:
classpath- The classpath. Must not be null. Can be empty.
-
bootstrapClasspath
Adds the given values to the end of the bootstrap classpath for the process.- Specified by:
bootstrapClasspathin interfaceJavaForkOptions- Parameters:
classpath- The classpath.- Returns:
- this
-
getMinHeapSize
Returns the minimum heap size for the process, if any.- Specified by:
getMinHeapSizein interfaceJavaForkOptions- Returns:
- The minimum heap size. Returns null if the default minimum heap size should be used.
-
setMinHeapSize
Sets the minimum heap size for the process.- Specified by:
setMinHeapSizein interfaceJavaForkOptions- Parameters:
heapSize- The minimum heap size. Use null for the default minimum heap size.
-
getDefaultCharacterEncoding
Returns the default character encoding to use.- Specified by:
getDefaultCharacterEncodingin interfaceJavaForkOptions- Returns:
- The default character encoding. Returns null if the
default character encoding of this JVMshould be used.
-
setDefaultCharacterEncoding
Sets the default character encoding to use. Note: Many JVM implementations support the setting of this attribute via system property on startup (namely, thefile.encodingproperty). For JVMs where this is the case, setting thefile.encodingproperty viaJavaForkOptions.setSystemProperties(java.util.Map)or similar will have no effect as this value will be overridden by the value specified byJavaForkOptions.getDefaultCharacterEncoding().- Specified by:
setDefaultCharacterEncodingin interfaceJavaForkOptions- Parameters:
defaultCharacterEncoding- The default character encoding. Use null to usethis JVM's default charset
-
getMaxHeapSize
Returns the maximum heap size for the process, if any.- Specified by:
getMaxHeapSizein interfaceJavaForkOptions- Returns:
- The maximum heap size. Returns null if the default maximum heap size should be used.
-
setMaxHeapSize
Sets the maximum heap size for the process.- Specified by:
setMaxHeapSizein interfaceJavaForkOptions- Parameters:
heapSize- The heap size. Use null for the default maximum heap size.
-
getEnableAssertions
public boolean getEnableAssertions()Returns true if assertions are enabled for the process.- Specified by:
getEnableAssertionsin interfaceJavaForkOptions- Returns:
- true if assertions are enabled, false if disabled
-
setEnableAssertions
public void setEnableAssertions(boolean enabled) Enable or disable assertions for the process.- Specified by:
setEnableAssertionsin interfaceJavaForkOptions- Parameters:
enabled- true to enable assertions, false to disable.
-
getDebug
public boolean getDebug()Returns true if debugging is enabled for the process. When enabled, the process is started suspended and listening on port 5005.- Specified by:
getDebugin interfaceJavaForkOptions- Returns:
- true when debugging is enabled, false to disable.
-
setDebug
public void setDebug(boolean enabled) Enable or disable debugging for the process. When enabled, the process is started suspended and listening on port 5005.- Specified by:
setDebugin interfaceJavaForkOptions- Parameters:
enabled- true to enable debugging, false to disable.
-
getMain
Returns the fully qualified name of the Main class to be executed.- Specified by:
getMainin interfaceJavaExecSpec
-
setMain
Sets the fully qualified name of the main class to be executed.- Specified by:
setMainin interfaceJavaExecSpec- Parameters:
mainClassName- the fully qualified name of the main class to be executed.- Returns:
- this
-
getArgs
Returns the arguments passed to the main class to be executed.- Specified by:
getArgsin interfaceJavaExecSpec
-
setArgs
Sets the args for the main class to be executed.- Specified by:
setArgsin interfaceJavaExecSpec- Parameters:
applicationArgs- Args for the main class.- Returns:
- this
-
setArgs
Sets the args for the main class to be executed.- Specified by:
setArgsin interfaceJavaExecSpec- Parameters:
applicationArgs- Args for the main class.- Returns:
- this
-
args
Adds args for the main class to be executed.- Specified by:
argsin interfaceJavaExecSpec- Parameters:
args- Args for the main class.- Returns:
- this
-
args
Adds args for the main class to be executed.- Specified by:
argsin interfaceJavaExecSpec- Parameters:
args- Args for the main class.- Returns:
- this
-
setClasspath
Sets the classpath for executing the main class.- Specified by:
setClasspathin interfaceJavaExecSpec- Parameters:
classpath- the classpath- Returns:
- this
-
classpath
Adds elements to the classpath for executing the main class.- Specified by:
classpathin interfaceJavaExecSpec- Parameters:
paths- classpath elements- Returns:
- this
-
getClasspath
Returns the classpath for executing the main class.- Specified by:
getClasspathin interfaceJavaExecSpec
-
copyTo
Copies these options to the given options.- Specified by:
copyToin interfaceJavaForkOptions- Parameters:
options- The target options.- Returns:
- this
-
getExecutable
Returns the name of the executable to use.- Specified by:
getExecutablein interfaceProcessForkOptions- Returns:
- The executable.
-
setExecutable
Sets the name of the executable to use.- Specified by:
setExecutablein interfaceProcessForkOptions- Parameters:
executable- The executable. Must not be null.
-
setExecutable
Sets the name of the executable to use.- Specified by:
setExecutablein interfaceProcessForkOptions- Parameters:
executable- The executable. Must not be null.
-
executable
Sets the name of the executable to use.- Specified by:
executablein interfaceProcessForkOptions- Parameters:
executable- The executable. Must not be null.- Returns:
- this
-
getWorkingDir
Returns the working directory for the process. Defaults to the project directory.- Specified by:
getWorkingDirin interfaceProcessForkOptions- Returns:
- The working directory. Never returns null.
-
setWorkingDir
Sets the working directory for the process.- Specified by:
setWorkingDirin interfaceProcessForkOptions- Parameters:
dir- The working directory. Must not be null.
-
setWorkingDir
Sets the working directory for the process. The supplied argument is evaluated as perProject.file(Object).- Specified by:
setWorkingDirin interfaceProcessForkOptions- Parameters:
dir- The working directory. Must not be null.
-
workingDir
Sets the working directory for the process. The supplied argument is evaluated as perProject.file(Object).- Specified by:
workingDirin interfaceProcessForkOptions- Parameters:
dir- The working directory. Must not be null.- Returns:
- this
-
getEnvironment
The environment variables to use for the process. Defaults to the environment of this process.- Specified by:
getEnvironmentin interfaceProcessForkOptions- Returns:
- The environment. Returns an empty map when there are no environment variables.
-
setEnvironment
Sets the environment variable to use for the process.- Specified by:
setEnvironmentin interfaceProcessForkOptions- Parameters:
environmentVariables- The environment variables. Must not be null.
-
environment
Adds an environment variable to the environment for this process.- Specified by:
environmentin interfaceProcessForkOptions- Parameters:
name- The name of the variable.value- The value for the variable. Must not be null.- Returns:
- this
-
environment
Adds some environment variables to the environment for this process.- Specified by:
environmentin interfaceProcessForkOptions- Parameters:
environmentVariables- The environment variables. Must not be null.- Returns:
- this
-
copyTo
Copies these options to the given target options.- Specified by:
copyToin interfaceProcessForkOptions- Parameters:
target- The target options- Returns:
- this
-
setStandardInput
Sets the standard input stream for the process executing the command. The stream is closed after the process completes.- Specified by:
setStandardInputin interfaceBaseExecSpec- Parameters:
inputStream- The standard input stream for the process. Must not be null.- Returns:
- this
-
getStandardInput
Returns the standard input stream for the process executing the command. The stream is closed after the process completes. Defaults to an empty stream.- Specified by:
getStandardInputin interfaceBaseExecSpec- Returns:
- The standard input stream.
-
setStandardOutput
Sets the output stream to consume standard output from the process executing the command. The stream is closed after the process completes.- Specified by:
setStandardOutputin interfaceBaseExecSpec- Parameters:
outputStream- The standard output stream for the process. Must not be null.- Returns:
- this
-
getStandardOutput
Returns the output stream to consume standard output from the process executing the command. Defaults toSystem.out.- Specified by:
getStandardOutputin interfaceBaseExecSpec- Returns:
- The output stream
-
setErrorOutput
Sets the output stream to consume standard error from the process executing the command. The stream is closed after the process completes.- Specified by:
setErrorOutputin interfaceBaseExecSpec- Parameters:
outputStream- The standard output error stream for the process. Must not be null.- Returns:
- this
-
getErrorOutput
Returns the output stream to consume standard error from the process executing the command. Default toSystem.err.- Specified by:
getErrorOutputin interfaceBaseExecSpec- Returns:
- The error output stream.
-
setIgnoreExitValue
Sets whether a non-zero exit value is ignored, or an exception thrown.- Specified by:
setIgnoreExitValuein interfaceBaseExecSpec- Parameters:
ignoreExitValue- whether a non-zero exit value is ignored, or an exception thrown- Returns:
- this
-
isIgnoreExitValue
Tells whether a non-zero exit value is ignored, or an exception thrown. Defaults tofalse.- Specified by:
isIgnoreExitValuein interfaceBaseExecSpec- Returns:
- whether a non-zero exit value is ignored, or an exception thrown
-
getCommandLine
Returns the full command line, including the executable plus its arguments.- Specified by:
getCommandLinein interfaceBaseExecSpec- Returns:
- The full command line, including the executable plus its arguments
-