Gradle JavaExec Task Type: Difference between revisions
Line 5: | Line 5: | ||
=Internal= | =Internal= | ||
* [[Gradle_Java_Plugin#jar_Task|Java Plugin]] | |||
* [[Gradle_Task#Java_Plugin_Predefined_Task_Types|Gradle Tasks]] | * [[Gradle_Task#Java_Plugin_Predefined_Task_Types|Gradle Tasks]] | ||
=Overview= | =Overview= | ||
Executes a Java application as a child process. To get details on the actual java command line, execute Gradle with [[Gradle_Command_Line#-i.2C--info|-i command line option]]. While the execution task name can be arbitrary, "run" is usually a good choice. | Executes a Java application as a child process. To get details on the actual java command line, execute Gradle with [[Gradle_Command_Line#-i.2C--info|-i command line option]]. While the execution task name can be arbitrary, "run" is usually a good choice. |
Revision as of 07:30, 28 March 2021
External
- https://docs.gradle.org/current/dsl/org.gradle.api.tasks.JavaExec.html
- https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/JavaExec.html
- https://www.baeldung.com/gradle-run-java-main
Internal
Overview
Executes a Java application as a child process. To get details on the actual java command line, execute Gradle with -i command line option. While the execution task name can be arbitrary, "run" is usually a good choice.
task someTask(type: JavaExec) {
classpath = configurations.runtimeClasspath
main = 'myPackage.MyMainClass'
args = ['something', 'somethingelse']
jvmArgs = ['-Xmx12g']
environment "LD_LIBRARY_PATH", "/usr/local/lib"
systemProperties = [ "some.prop": "some.value", "some.other.prop": "some.other.value" ]
}
Configuration
classpath
TODO
classpath = sourceSets.main.runtimeClasspath
classpath = configurations.runtimeClasspath
main
The main class. Must be available on classpath.
main = 'playground.javaExec.Main'
args
"args" can be provided as a single string, but in this case, even if individual tokens are separated by space, the main() method will get just one single string as argument:
args 'A B C'
This will be passed to the Java main() method as args[0]:
arguments:
args[0]: X Y Z
To provide individual tokens, use this syntax:
args = ['A', 'B', 'C']
The list elements will be passed to the Java main() method as individual arguments:
arguments:
args[0]: A
args[1]: B
args[2]: C
jvmArgs
jvmArgs = ['-Xmx12g']
environment
Specifies a single environment variable, as a key value pair separated by comma. Multiple variable can be specified that way:
environment "SOME_ENV_VAR", "some value"
environment "SOME_OTHER_ENV_VAR", "some other value"
systemProperties
A Groovy map.
systemProperties = [ "some.prop": "some.value", "some.other.prop": "some.other.value" ]