# JavaExec

@DisableCachingByDefault(because = "Gradle would require more information to cache this task")
abstract class JavaExec : ConventionTask, JavaExecSpec(source)

Executes a Java application in a child process.

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

    plugins {
        id 'java'
    }

    task runApp(type: JavaExec) {
      classpath = sourceSets.main.runtimeClasspath

      mainClass = 'package.Main'

      // arguments to pass to the application
      args 'appArg1'
    }

    // Using and creating an Executable Jar
    jar {
      manifest {
        attributes('Main-Class': 'package.Main')
      }
    }

    task runExecutableJar(type: JavaExec) {
      // Executable jars can have only _one_ jar on the classpath.
      classpath = files(tasks.jar)

      // 'main' does not need to be specified

      // arguments to pass to the application
      args 'appArg1'
    }

Content copied to clipboard

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

Content copied to clipboard

Also, debug configuration can be explicitly set in debugOptions:

    task runApp(type: JavaExec) {
       ...

       debugOptions {
           enabled = true
           port = 5566
           server = true
           suspend = false
       }
    }

Content copied to clipboard

## Constructors

JavaExec
Link copied to clipboard
constructor()

## Properties

conventionMapping
Link copied to clipboard
open val conventionMapping: ConventionMapping
description
Link copied to clipboard
open var description: String
enabled
Link copied to clipboard
open var enabled: Boolean
extra
Link copied to clipboard
val ExtensionAware.extra: ExtraPropertiesExtension

The extra properties extension in this object's extension container.

group
Link copied to clipboard
open var group: String
impliesSubProjects
Link copied to clipboard
open var impliesSubProjects: Boolean
javaLauncher
Link copied to clipboard
val javaLauncher: Property<JavaLauncher>
jvmArguments
Link copied to clipboard
val jvmArguments: ListProperty<String>
mainClass
Link copied to clipboard
val mainClass: Property<String>
mainModule
Link copied to clipboard
val mainModule: Property<String>
modularity
Link copied to clipboard
val modularity: ModularitySpec
state
Link copied to clipboard
val state: TaskStateInternal
TASK_ACTION
Link copied to clipboard
val TASK_ACTION: String = "action"
TASK_CONSTRUCTOR_ARGS
Link copied to clipboard
val TASK_CONSTRUCTOR_ARGS: String = "constructorArgs"
TASK_DEPENDS_ON
Link copied to clipboard
val TASK_DEPENDS_ON: String = "dependsOn"
TASK_DESCRIPTION
Link copied to clipboard
val TASK_DESCRIPTION: String = "description"
TASK_GROUP
Link copied to clipboard
val TASK_GROUP: String = "group"
TASK_NAME
Link copied to clipboard
val TASK_NAME: String = "name"
TASK_OVERWRITE
Link copied to clipboard
val TASK_OVERWRITE: String = "overwrite"
TASK_TYPE
Link copied to clipboard
val TASK_TYPE: String = "type"
timeout
Link copied to clipboard
val timeout: Property<Duration>

## Functions

acceptServiceReferences
Link copied to clipboard
open fun acceptServiceReferences(serviceReferences: Set<ServiceReferenceSpec>)
appendParallelSafeAction
Link copied to clipboard
open fun appendParallelSafeAction(action: Action<in Task>)
args
Link copied to clipboard
open fun args(args: Iterable<out Any>): JavaExecSpec
open fun args(args: Array<Any>): JavaExec
bootstrapClasspath
Link copied to clipboard
open fun bootstrapClasspath(classpath: Array<Any>): JavaExec
classpath
Link copied to clipboard
open fun classpath(paths: Array<Any>): JavaExec
compareTo
Link copied to clipboard
open fun compareTo(otherTask: Task): Int
configure
Link copied to clipboard
open fun configure(closure: Closure): Task
abstract fun configure(cl: Closure): T
configure
Link copied to clipboard
inline fun <T : Any> ExtensionAware.configure(noinline configuration: T.() -> Unit)

Executes the given configuration block against the extension of the specified type.

conventionMapping
Link copied to clipboard
open fun conventionMapping(property: String, mapping: Callable<out Any>): Task
copyTo
Link copied to clipboard
open fun copyTo(options: JavaForkOptions): JavaExec
open fun copyTo(target: ProcessForkOptions): JavaExec
debugOptions
Link copied to clipboard
open fun debugOptions(action: Action<JavaDebugOptions>)
dependsOn
Link copied to clipboard
open fun dependsOn(paths: Array<Any>): Task
doFirst
Link copied to clipboard
open fun doFirst(action: Action<in Task>): Task
doLast
Link copied to clipboard
open fun doLast(action: Action<in Task>): Task
doNotTrackState
Link copied to clipboard
open fun doNotTrackState(reasonNotToTrackState: String)
environment
Link copied to clipboard
open fun environment(environmentVariables: Map<String, out Any>): JavaExec
open fun environment(name: String, value: Any): JavaExec
environment
Link copied to clipboard
inline fun JavaExec.environment(vararg environmentVariables: Pair<String, Any?>): JavaExec

Kotlin extension function for org.gradle.api.tasks.JavaExec.environment.

inline fun ProcessForkOptions.environment(vararg environmentVariables: Pair<String, Any?>): ProcessForkOptions

Kotlin extension function for org.gradle.process.ProcessForkOptions.environment.

exec
Link copied to clipboard
open fun exec()
executable
Link copied to clipboard
open fun executable(executable: Any): JavaExec
finalizedBy
Link copied to clipboard
open fun finalizedBy(paths: Array<Any>): Task
getActions
Link copied to clipboard
open fun getActions(): List<Action<in Task>>
getAllJvmArgs
Link copied to clipboard
open fun getAllJvmArgs(): List<String>
getAnt
Link copied to clipboard
open fun getAnt(): AntBuilder
getArgs
Link copied to clipboard
open fun getArgs(): List<String>
getArgumentProviders
Link copied to clipboard
open fun getArgumentProviders(): List<CommandLineArgumentProvider>
getAsDynamicObject
Link copied to clipboard
open fun getAsDynamicObject(): DynamicObject
getBootstrapClasspath
Link copied to clipboard
open fun getBootstrapClasspath(): FileCollection
getClasspath
Link copied to clipboard
open fun getClasspath(): FileCollection
getCommandLine
Link copied to clipboard
@Internal
open fun getCommandLine(): List<String>
getConvention
Link copied to clipboard
open fun getConvention(): Convention
getDebug
Link copied to clipboard
open fun getDebug(): Boolean
getDebugOptions
Link copied to clipboard
open fun getDebugOptions(): JavaDebugOptions
getDefaultCharacterEncoding
Link copied to clipboard
open fun getDefaultCharacterEncoding(): String
getDependsOn
Link copied to clipboard
open fun getDependsOn(): Set<Any>
getDestroyables
Link copied to clipboard
open fun getDestroyables(): TaskDestroyables
getDidWork
Link copied to clipboard
open fun getDidWork(): Boolean
getEnableAssertions
Link copied to clipboard
open fun getEnableAssertions(): Boolean
getEnvironment
Link copied to clipboard
@Internal
open fun getEnvironment(): Map<String, Any>
getErrorOutput
Link copied to clipboard
@Internal
open fun getErrorOutput(): OutputStream
getExecutable
Link copied to clipboard
@Internal(value = "covered by getJavaVersion")
@Nullable
open fun getExecutable(): String
getExecutionResult
Link copied to clipboard
@Internal
open fun getExecutionResult(): Provider<ExecResult>
Returns the result for the command run by this task.
getExtensions
Link copied to clipboard
open fun getExtensions(): ExtensionContainer
getFinalizedBy
Link copied to clipboard
open fun getFinalizedBy(): TaskDependency
getIdentityPath
Link copied to clipboard
open fun getIdentityPath(): Path
getInputs
Link copied to clipboard
open fun getInputs(): TaskInputsInternal
abstract fun getInputs(): TaskInputs
getJavaVersion
Link copied to clipboard
@Input
open fun getJavaVersion(): JavaVersion
Returns the version of the Java executable specified by getJavaLauncher.
getJvmArgs
Link copied to clipboard
open fun getJvmArgs(): List<String>
getJvmArgumentProviders
Link copied to clipboard
open fun getJvmArgumentProviders(): List<CommandLineArgumentProvider>
getJvmArguments
Link copied to clipboard
abstract fun getJvmArguments(): ListProperty<String>
getLifecycleDependencies
Link copied to clipboard
open fun getLifecycleDependencies(): TaskDependencyInternal
abstract fun getLifecycleDependencies(): TaskDependency
getLocalState
Link copied to clipboard
open fun getLocalState(): TaskLocalState
getLogger
Link copied to clipboard
open fun getLogger(): Logger
getLogging
Link copied to clipboard
open fun getLogging(): LoggingManager
getMainClass
Link copied to clipboard
abstract fun getMainClass(): Property<String>
getMainModule
Link copied to clipboard
abstract fun getMainModule(): Property<String>
getMaxHeapSize
Link copied to clipboard
open fun getMaxHeapSize(): String
getMinHeapSize
Link copied to clipboard
open fun getMinHeapSize(): String
getModularity
Link copied to clipboard
abstract fun getModularity(): ModularitySpec
getMustRunAfter
Link copied to clipboard
open fun getMustRunAfter(): TaskDependency
getName
Link copied to clipboard
open fun getName(): String
getOnlyIf
Link copied to clipboard
open fun getOnlyIf(): Spec<in TaskInternal>
getOutputs
Link copied to clipboard
open fun getOutputs(): TaskOutputsInternal
abstract fun getOutputs(): TaskOutputs
getPath
Link copied to clipboard
open fun getPath(): String
getProject
Link copied to clipboard
open fun getProject(): Project
getReasonNotToTrackState
Link copied to clipboard
open fun getReasonNotToTrackState(): Optional<String>
getReasonTaskIsIncompatibleWithConfigurationCache
Link copied to clipboard
open fun getReasonTaskIsIncompatibleWithConfigurationCache(): Optional<String>
getRequiredServices
Link copied to clipboard
open fun getRequiredServices(): TaskRequiredServices
getSharedResources
Link copied to clipboard
open fun getSharedResources(): List<ResourceLock>
abstract fun getSharedResources(): List<out ResourceLock>
getShouldRunAfter
Link copied to clipboard
open fun getShouldRunAfter(): TaskDependency
getStandardInput
Link copied to clipboard
@Internal
open fun getStandardInput(): InputStream
getStandardOutput
Link copied to clipboard
@Internal
open fun getStandardOutput(): OutputStream
getStandardOutputCapture
Link copied to clipboard
open fun getStandardOutputCapture(): StandardOutputCapture
getState
Link copied to clipboard
abstract fun getState(): TaskState
getSystemProperties
Link copied to clipboard
open fun getSystemProperties(): Map<String, Any>
getTaskActions
Link copied to clipboard
open fun getTaskActions(): List<InputChangesAwareTaskAction>
getTaskDependencies
Link copied to clipboard
open fun getTaskDependencies(): TaskDependencyInternal
abstract fun getTaskDependencies(): TaskDependency
getTaskIdentity
Link copied to clipboard
open fun getTaskIdentity(): TaskIdentity<out Any>
getTemporaryDir
Link copied to clipboard
open fun getTemporaryDir(): File
getTemporaryDirFactory
Link copied to clipboard
open fun getTemporaryDirFactory(): Factory<File>
getWorkingDir
Link copied to clipboard
@Internal
open fun getWorkingDir(): File
hasProperty
Link copied to clipboard
open fun hasProperty(propertyName: String): Boolean
hasTaskActions
Link copied to clipboard
open fun hasTaskActions(): Boolean
injectIntoNewInstance
Link copied to clipboard
open fun <T : Task?> injectIntoNewInstance(project: ProjectInternal, identity: TaskIdentity<T>, factory: Callable<T>): T
isCompatibleWithConfigurationCache
Link copied to clipboard
open fun isCompatibleWithConfigurationCache(): Boolean
isEnabled
Link copied to clipboard
open fun isEnabled(): Boolean
isHasCustomActions
Link copied to clipboard
open fun isHasCustomActions(): Boolean
isIgnoreExitValue
Link copied to clipboard
@Input
open fun isIgnoreExitValue(): Boolean
jvmArgs
Link copied to clipboard
open fun jvmArgs(arguments: Iterable<out Any>): JavaExec
open fun jvmArgs(arguments: Array<Any>): JavaExec
mustRunAfter
Link copied to clipboard
open fun mustRunAfter(paths: Array<Any>): Task
notCompatibleWithConfigurationCache
Link copied to clipboard
open fun notCompatibleWithConfigurationCache(reason: String)
onlyIf
Link copied to clipboard
open fun onlyIf(spec: Spec<in Task>)
prependParallelSafeAction
Link copied to clipboard
open fun prependParallelSafeAction(action: Action<in Task>)
property
Link copied to clipboard
open fun property(propertyName: String): Any
setActions
Link copied to clipboard
open fun setActions(replacements: List<Action<in Task>>)
setAllJvmArgs
Link copied to clipboard
open fun setAllJvmArgs(arguments: Iterable<out Any>)
open fun setAllJvmArgs(arguments: List<String>)
setArgs
Link copied to clipboard
open fun setArgs(applicationArgs: Iterable<out Any>): JavaExec
open fun setArgs(applicationArgs: List<String>): JavaExec
setArgsString
Link copied to clipboard
open fun setArgsString(args: String): JavaExec
Parses an argument list from `args` and passes it to setArgs.
setBootstrapClasspath
Link copied to clipboard
open fun setBootstrapClasspath(classpath: FileCollection)
setClasspath
Link copied to clipboard
open fun setClasspath(classpath: FileCollection): JavaExec
setDebug
Link copied to clipboard
open fun setDebug(enabled: Boolean)
setDefaultCharacterEncoding
Link copied to clipboard
open fun setDefaultCharacterEncoding(defaultCharacterEncoding: String)
setDependsOn
Link copied to clipboard
open fun setDependsOn(dependsOn: Iterable<out Any>)
setDidWork
Link copied to clipboard
open fun setDidWork(didWork: Boolean)
setEnableAssertions
Link copied to clipboard
open fun setEnableAssertions(enabled: Boolean)
setEnvironment
Link copied to clipboard
open fun setEnvironment(environmentVariables: Map<String, out Any>)
setEnvironment
Link copied to clipboard
inline fun ProcessForkOptions.setEnvironment(vararg environmentVariables: Pair<String, Any?>)

Kotlin extension function for org.gradle.process.ProcessForkOptions.setEnvironment.

setErrorOutput
Link copied to clipboard
open fun setErrorOutput(outputStream: OutputStream): JavaExec
setExecutable
Link copied to clipboard
open fun setExecutable(executable: Any)
open fun setExecutable(executable: String)
setFinalizedBy
Link copied to clipboard
open fun setFinalizedBy(finalizedByTasks: Iterable<out Any>)
setIgnoreExitValue
Link copied to clipboard
open fun setIgnoreExitValue(ignoreExitValue: Boolean): JavaExecSpec
setJvmArgs
Link copied to clipboard
open fun setJvmArgs(arguments: Iterable<out Any>)
open fun setJvmArgs(arguments: List<String>)
setMain
Link copied to clipboard
open fun setMain(main: String): JavaExecSpec
setMaxHeapSize
Link copied to clipboard
open fun setMaxHeapSize(heapSize: String)
setMinHeapSize
Link copied to clipboard
open fun setMinHeapSize(heapSize: String)
setMustRunAfter
Link copied to clipboard
open fun setMustRunAfter(mustRunAfterTasks: Iterable<out Any>)
setOnlyIf
Link copied to clipboard
open fun setOnlyIf(spec: Spec<in Task>)
setProperty
Link copied to clipboard
open fun setProperty(name: String, value: Any)
setShouldRunAfter
Link copied to clipboard
open fun setShouldRunAfter(shouldRunAfterTasks: Iterable<out Any>)
setStandardInput
Link copied to clipboard
open fun setStandardInput(inputStream: InputStream): JavaExec
setStandardOutput
Link copied to clipboard
open fun setStandardOutput(outputStream: OutputStream): JavaExec
setSystemProperties
Link copied to clipboard
open fun setSystemProperties(properties: Map<String, out Any>)
setWorkingDir
Link copied to clipboard
open fun setWorkingDir(dir: File)
open fun setWorkingDir(dir: Any)
shouldRunAfter
Link copied to clipboard
open fun shouldRunAfter(paths: Array<Any>): TaskDependency
systemProperties
Link copied to clipboard
open fun systemProperties(properties: Map<String, out Any>): JavaExec
systemProperties
Link copied to clipboard
inline fun JavaExec.systemProperties(vararg properties: Pair<String, Any?>): JavaExec

Kotlin extension function for org.gradle.api.tasks.JavaExec.systemProperties.

inline fun JavaForkOptions.systemProperties(vararg properties: Pair<String, Any?>): JavaForkOptions

Kotlin extension function for org.gradle.process.JavaForkOptions.systemProperties.

systemProperty
Link copied to clipboard
open fun systemProperty(name: String, value: Any): JavaExec
the
Link copied to clipboard
inline fun <T : Any> ExtensionAware.the(): T

Returns the extension of the specified type.

fun <T : Any> ExtensionAware.the(extensionType: KClass<T>): T

Returns the extension of the specified extensionType.

usesService
Link copied to clipboard
open fun usesService(service: Provider<out BuildService<out Any>>)
workingDir
Link copied to clipboard
open fun workingDir(dir: Any): JavaExec