I am trying to run my app using a Gradle javaexec task. However, jvmargs and args are not passed to the command execution. Why?
task runArgoDev(type: JavaExec) {
main = "org.app.ArgoDevRunner"
classpath = configurations.testRuntime
project.ext.jvmargs = ['-Xdock:name=Argo', '-Xmx512m', '-Dfile.encoding=UTF-8', '-Dapple.awt.textantialiasing=on', '-ea']
project.ext.args = ['-initParameter', 'implicit-scrollpane-support=true']
}
However, this is only available from Gradle 4.9 onward. Let’s see what this would look like using a JavaExec task. First, we need to define it in our build.gradle:
protected org.gradle.process.internal.ExecActionFactory Returns the name of the executable to use. Returns the result for the command run by this task. Configures the java executable to be used to run the tests. Returns the version of the Java executable specified by getExecutable ().
Passing Arguments to Other Applications In some cases, we might want to pass some arguments to a third-party application from Gradle. Here, we use the commandLine property of the task to pass the executable along with any arguments. Again, we split the input based on spaces.
First, we need to define it in our build.gradle: Let’s take a closer look at what we did. We first read the arguments from a project property. Since this contains all the arguments as one string, we then use the split method to obtain an array of arguments. Next, we pass this array to the args property of our JavaExec task.
Above code doesn't have the desired effect because it sets extra properties on the project
object, instead of configuring the task. Correct is jvmArgs = ...
and args = ...
. (It's also possible to omit =
, [
, and ]
.)
Here is example, to pass program args and jvmargs to run task in gradle.
run {
args 'server', 'test.yml'
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With