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>
RhinoShellExec
public class JavaExec extends org.gradle.api.internal.ConventionTask implements JavaExecSpec
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
Task.Namer
TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE
Constructor | Description |
---|---|
JavaExec() |
Modifier and Type | Method | Description |
---|---|---|
JavaExecSpec |
args(Iterable<?> args) |
Adds args for the main class to be executed.
|
JavaExec |
args(Object... args) |
Adds args for the main class to be executed.
|
JavaExec |
bootstrapClasspath(Object... classpath) |
Adds the given values to the end of the bootstrap classpath for the process.
|
JavaExec |
classpath(Object... paths) |
Adds elements to the classpath for executing the main class.
|
JavaExec |
copyTo(JavaForkOptions options) |
Copies these options to the given options.
|
JavaExec |
copyTo(ProcessForkOptions target) |
Copies these options to the given target options.
|
JavaExec |
environment(String name,
Object value) |
Adds an environment variable to the environment for this process.
|
JavaExec |
environment(Map<String,?> environmentVariables) |
Adds some environment variables to the environment for this process.
|
void |
exec() |
|
JavaExec |
executable(Object executable) |
Sets the name of the executable to use.
|
List<String> |
getAllJvmArgs() |
Returns the full set of arguments to use to launch the JVM for the process.
|
List<String> |
getArgs() |
Returns the arguments passed to the main class to be executed.
|
List<CommandLineArgumentProvider> |
getArgumentProviders() |
Argument providers for the application.
|
FileCollection |
getBootstrapClasspath() |
Returns the bootstrap classpath to use for the process.
|
FileCollection |
getClasspath() |
Returns the classpath for executing the main class.
|
List<String> |
getCommandLine() |
Returns the full command line, including the executable plus its arguments.
|
boolean |
getDebug() |
Determines whether debugging is enabled for the test process.
|
String |
getDefaultCharacterEncoding() |
Returns the default character encoding to use.
|
boolean |
getEnableAssertions() |
Returns true if assertions are enabled for the process.
|
Map<String,Object> |
getEnvironment() |
The environment variables to use for the process.
|
OutputStream |
getErrorOutput() |
Returns the output stream to consume standard error from the process executing the command.
|
protected org.gradle.process.internal.ExecActionFactory |
getExecActionFactory() |
|
String |
getExecutable() |
Returns the name of the executable to use.
|
JavaVersion |
getJavaVersion() |
Returns the version of the Java executable specified by
getExecutable() . |
List<String> |
getJvmArgs() |
Returns the extra arguments to use to launch the JVM for the process.
|
List<CommandLineArgumentProvider> |
getJvmArgumentProviders() |
Command line argument providers for the java process to fork.
|
String |
getMain() |
Returns the fully qualified name of the Main class to be executed.
|
String |
getMaxHeapSize() |
Returns the maximum heap size for the process, if any.
|
String |
getMinHeapSize() |
Returns the minimum heap size for the process, if any.
|
InputStream |
getStandardInput() |
Returns the standard input stream for the process executing the command.
|
OutputStream |
getStandardOutput() |
Returns the output stream to consume standard output from the process executing the command.
|
Map<String,Object> |
getSystemProperties() |
Returns the system properties which will be used for the process.
|
File |
getWorkingDir() |
Returns the working directory for the process.
|
boolean |
isIgnoreExitValue() |
Tells whether a non-zero exit value is ignored, or an exception thrown.
|
JavaExec |
jvmArgs(Iterable<?> arguments) |
Adds some arguments to use to launch the JVM for the process.
|
JavaExec |
jvmArgs(Object... arguments) |
Adds some arguments to use to launch the JVM for the process.
|
void |
setAllJvmArgs(Iterable<?> arguments) |
Sets the full set of arguments to use to launch the JVM for the process.
|
void |
setAllJvmArgs(List<String> arguments) |
Sets the full set of arguments to use to launch the JVM for the process.
|
JavaExec |
setArgs(Iterable<?> applicationArgs) |
Sets the args for the main class to be executed.
|
JavaExec |
setArgs(List<String> applicationArgs) |
Sets the args for the main class to be executed.
|
JavaExec |
setArgsString(String args) |
Parses an argument list from
args and passes it to setArgs(List) . |
void |
setBootstrapClasspath(FileCollection classpath) |
Sets the bootstrap classpath to use for the process.
|
JavaExec |
setClasspath(FileCollection classpath) |
Sets the classpath for executing the main class.
|
void |
setDebug(boolean enabled) |
Enable or disable debugging for the process.
|
void |
setDefaultCharacterEncoding(String defaultCharacterEncoding) |
Sets the default character encoding to use.
|
void |
setEnableAssertions(boolean enabled) |
Enable or disable assertions for the process.
|
void |
setEnvironment(Map<String,?> environmentVariables) |
Sets the environment variable to use for the process.
|
JavaExec |
setErrorOutput(OutputStream outputStream) |
Sets the output stream to consume standard error from the process executing the command.
|
void |
setExecutable(Object executable) |
Sets the name of the executable to use.
|
void |
setExecutable(String executable) |
Sets the name of the executable to use.
|
JavaExecSpec |
setIgnoreExitValue(boolean ignoreExitValue) |
Sets whether a non-zero exit value is ignored, or an exception thrown.
|
void |
setJvmArgs(Iterable<?> arguments) |
Sets the extra arguments to use to launch the JVM for the process.
|
void |
setJvmArgs(List<String> arguments) |
Sets the extra arguments to use to launch the JVM for the process.
|
JavaExec |
setMain(String mainClassName) |
Sets the fully qualified name of the main class to be executed.
|
void |
setMaxHeapSize(String heapSize) |
Sets the maximum heap size for the process.
|
void |
setMinHeapSize(String heapSize) |
Sets the minimum heap size for the process.
|
JavaExec |
setStandardInput(InputStream inputStream) |
Sets the standard input stream for the process executing the command.
|
JavaExec |
setStandardOutput(OutputStream outputStream) |
Sets the output stream to consume standard output from the process executing the command.
|
void |
setSystemProperties(Map<String,?> properties) |
Sets the system properties to use for the process.
|
void |
setWorkingDir(File dir) |
Sets the working directory for the process.
|
void |
setWorkingDir(Object dir) |
Sets the working directory for the process.
|
JavaExec |
systemProperties(Map<String,?> properties) |
Adds some system properties to use for the process.
|
JavaExec |
systemProperty(String name,
Object value) |
Adds a system property to use for the process.
|
JavaExec |
workingDir(Object dir) |
Sets the working directory for the process.
|
conventionMapping, conventionMapping, getConventionMapping
newInputDirectory, newInputFile, newOutputDirectory, newOutputFile
appendParallelSafeAction, compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getAsDynamicObject, getConvention, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getIdentityPath, getImpliesSubProjects, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOnlyIf, getOutputs, getPath, getProject, getServices, getShouldRunAfter, getStandardOutputCapture, getState, getTaskActions, getTaskDependencies, getTaskIdentity, getTemporaryDir, getTemporaryDirFactory, getTimeout, hasProperty, hasTaskActions, injectIntoNewInstance, isEnabled, isHasCustomActions, mustRunAfter, onlyIf, onlyIf, prependParallelSafeAction, property, replaceLogger, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setImpliesSubProjects, setMustRunAfter, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, toString
@Inject protected org.gradle.process.internal.ExecActionFactory getExecActionFactory()
public void exec()
public List<String> getAllJvmArgs()
getAllJvmArgs
in interface JavaForkOptions
public void setAllJvmArgs(List<String> arguments)
setAllJvmArgs
in interface JavaForkOptions
arguments
- The arguments. Must not be null.public void setAllJvmArgs(Iterable<?> arguments)
setAllJvmArgs
in interface JavaForkOptions
arguments
- The arguments. Must not be null.public List<String> getJvmArgs()
getJvmArgs
in interface JavaForkOptions
public void setJvmArgs(List<String> arguments)
setJvmArgs
in interface JavaForkOptions
arguments
- The arguments. Must not be null.public void setJvmArgs(Iterable<?> arguments)
setJvmArgs
in interface JavaForkOptions
arguments
- The arguments. Must not be null.public JavaExec jvmArgs(Iterable<?> arguments)
jvmArgs
in interface JavaForkOptions
arguments
- The arguments. Must not be null.public JavaExec jvmArgs(Object... arguments)
jvmArgs
in interface JavaForkOptions
arguments
- The arguments.public Map<String,Object> getSystemProperties()
getSystemProperties
in interface JavaForkOptions
public void setSystemProperties(Map<String,?> properties)
setSystemProperties
in interface JavaForkOptions
properties
- The system properties. Must not be null.public JavaExec systemProperties(Map<String,?> properties)
systemProperties
in interface JavaForkOptions
properties
- The system properties. Must not be null.public JavaExec systemProperty(String name, Object value)
systemProperty
in interface JavaForkOptions
name
- The name of the propertyvalue
- The value for the property. May be null.public FileCollection getBootstrapClasspath()
getBootstrapClasspath
in interface JavaForkOptions
public void setBootstrapClasspath(FileCollection classpath)
setBootstrapClasspath
in interface JavaForkOptions
classpath
- The classpath. Must not be null. Can be empty.public JavaExec bootstrapClasspath(Object... classpath)
bootstrapClasspath
in interface JavaForkOptions
classpath
- The classpath.public String getMinHeapSize()
getMinHeapSize
in interface JavaForkOptions
public void setMinHeapSize(String heapSize)
setMinHeapSize
in interface JavaForkOptions
heapSize
- The minimum heap size. Use null for the default minimum heap size.public String getDefaultCharacterEncoding()
getDefaultCharacterEncoding
in interface JavaForkOptions
default character encoding of this JVM
should be used.public void setDefaultCharacterEncoding(String defaultCharacterEncoding)
file.encoding
property). For JVMs
where this is the case, setting the file.encoding
property via JavaForkOptions.setSystemProperties(java.util.Map)
or similar will have no effect as
this value will be overridden by the value specified by JavaForkOptions.getDefaultCharacterEncoding()
.setDefaultCharacterEncoding
in interface JavaForkOptions
defaultCharacterEncoding
- The default character encoding. Use null to use this JVM's default charset
public String getMaxHeapSize()
getMaxHeapSize
in interface JavaForkOptions
public void setMaxHeapSize(String heapSize)
setMaxHeapSize
in interface JavaForkOptions
heapSize
- The heap size. Use null for the default maximum heap size.public boolean getEnableAssertions()
getEnableAssertions
in interface JavaForkOptions
public void setEnableAssertions(boolean enabled)
setEnableAssertions
in interface JavaForkOptions
enabled
- true to enable assertions, false to disable.public boolean getDebug()
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
Test.getForkEvery()
.getDebug
in interface JavaForkOptions
public void setDebug(boolean enabled)
setDebug
in interface JavaForkOptions
enabled
- true to enable debugging, false to disable.public String getMain()
getMain
in interface JavaExecSpec
public JavaExec setMain(String mainClassName)
setMain
in interface JavaExecSpec
mainClassName
- the fully qualified name of the main class to be executed.public List<String> getArgs()
getArgs
in interface JavaExecSpec
@Incubating public JavaExec setArgsString(String args)
args
and passes it to setArgs(List)
.
The parser supports both single quote ('
) and double quote ("
) as quote delimiters.
For example, to pass the argument foo bar
, use "foo bar"
.
Note: the parser does not support using backslash to escape quotes. If this is needed,
use the other quote delimiter around it.
For example, to pass the argument 'singly quoted'
, use "'singly quoted'"
.
args
- Args for the main class. Will be parsed into an argument list.public JavaExec setArgs(List<String> applicationArgs)
setArgs
in interface JavaExecSpec
applicationArgs
- Args for the main class.public JavaExec setArgs(Iterable<?> applicationArgs)
setArgs
in interface JavaExecSpec
applicationArgs
- Args for the main class.public JavaExec args(Object... args)
args
in interface JavaExecSpec
args
- Args for the main class.public JavaExecSpec args(Iterable<?> args)
args
in interface JavaExecSpec
args
- Args for the main class.public List<CommandLineArgumentProvider> getArgumentProviders()
getArgumentProviders
in interface JavaExecSpec
public JavaExec setClasspath(FileCollection classpath)
setClasspath
in interface JavaExecSpec
classpath
- the classpathpublic JavaExec classpath(Object... paths)
classpath
in interface JavaExecSpec
paths
- classpath elementspublic FileCollection getClasspath()
getClasspath
in interface JavaExecSpec
public JavaExec copyTo(JavaForkOptions options)
copyTo
in interface JavaForkOptions
options
- The target options.@Input @Incubating public JavaVersion getJavaVersion()
getExecutable()
.@Internal("covered by getJavaVersion") @Nullable public String getExecutable()
getExecutable
in interface ProcessForkOptions
public void setExecutable(String executable)
setExecutable
in interface ProcessForkOptions
executable
- The executable. Must not be null.public void setExecutable(Object executable)
setExecutable
in interface ProcessForkOptions
executable
- The executable. Must not be null.public JavaExec executable(Object executable)
executable
in interface ProcessForkOptions
executable
- The executable. Must not be null.@Internal public File getWorkingDir()
getWorkingDir
in interface ProcessForkOptions
public void setWorkingDir(File dir)
setWorkingDir
in interface ProcessForkOptions
dir
- The working directory. Must not be null.public void setWorkingDir(Object dir)
Project.file(Object)
.setWorkingDir
in interface ProcessForkOptions
dir
- The working directory. Must not be null.public JavaExec workingDir(Object dir)
Project.file(Object)
.workingDir
in interface ProcessForkOptions
dir
- The working directory. Must not be null.@Internal public Map<String,Object> getEnvironment()
getEnvironment
in interface ProcessForkOptions
public void setEnvironment(Map<String,?> environmentVariables)
setEnvironment
in interface ProcessForkOptions
environmentVariables
- The environment variables. Must not be null.public JavaExec environment(String name, Object value)
environment
in interface ProcessForkOptions
name
- The name of the variable.value
- The value for the variable. Must not be null.public JavaExec environment(Map<String,?> environmentVariables)
environment
in interface ProcessForkOptions
environmentVariables
- The environment variables. Must not be null.public JavaExec copyTo(ProcessForkOptions target)
copyTo
in interface ProcessForkOptions
target
- The target optionspublic JavaExec setStandardInput(InputStream inputStream)
setStandardInput
in interface BaseExecSpec
inputStream
- The standard input stream for the process. Must not be null.@Internal public InputStream getStandardInput()
getStandardInput
in interface BaseExecSpec
public JavaExec setStandardOutput(OutputStream outputStream)
setStandardOutput
in interface BaseExecSpec
outputStream
- The standard output stream for the process. Must not be null.@Internal public OutputStream getStandardOutput()
System.out
.getStandardOutput
in interface BaseExecSpec
public JavaExec setErrorOutput(OutputStream outputStream)
setErrorOutput
in interface BaseExecSpec
outputStream
- The standard output error stream for the process. Must not be null.@Internal public OutputStream getErrorOutput()
System.err
.getErrorOutput
in interface BaseExecSpec
public JavaExecSpec setIgnoreExitValue(boolean ignoreExitValue)
setIgnoreExitValue
in interface BaseExecSpec
ignoreExitValue
- whether a non-zero exit value is ignored, or an exception thrown@Input public boolean isIgnoreExitValue()
false
.isIgnoreExitValue
in interface BaseExecSpec
@Internal public List<String> getCommandLine()
getCommandLine
in interface BaseExecSpec
public List<CommandLineArgumentProvider> getJvmArgumentProviders()
getJvmArgumentProviders
in interface JavaForkOptions