Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle javaexec task is ignoring jvmargs

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']

}

like image 242
user3531297 Avatar asked Apr 14 '14 09:04

user3531297


People also ask

Is it possible to use javaexec with Gradle?

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:

What is the use of execactionfactory in 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 ().

How do I pass arguments from one Gradle task to another?

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.

How do I get the arguments of a javaexec task?

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.


Video Answer


2 Answers

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 ].)

like image 143
Peter Niederwieser Avatar answered Oct 19 '22 15:10

Peter Niederwieser


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'
}
like image 8
Hrishikesh Mishra Avatar answered Oct 19 '22 15:10

Hrishikesh Mishra