One of the tasks the gradle application plugin creates is called 'run'. This works great but how do I pass command line arguments to the application it is running? Gradle seems to want to interpret anything I pass on the command line.
Regards, Glen
|
Hello Glen,
The run task is of type JavaExec. As you can see in the DSL Documentation of JavaExec ( http://gradle.org/docs/current/dsl/org.gradle.api.tasks.JavaExec.html#org.gradle.api.tasks.JavaExec:args ), you can pass parameters to the task using "args": run{ args '-i' } regards, René
|
Thanks René,
That lets me pass arguments by hard coding them into my build.gradle but I was wanting to pass args from the gradle command line. For example something like: gradle run arg1 arg2 ...
Regards, Glen On 6 March 2012 19:09, Rene Groeschke <[hidden email]> wrote:
|
On 07/03/2012 04:04, Glen Stampoultzis wrote:
> That lets me pass arguments by hard coding them into my build.gradle but I was wanting to > pass args from the gradle command line. For example something like: > > gradle run arg1 arg2 ... I was suspecting that. I asked the same question some time ago, and I had no satisfying answer: I wanted a built-in way to specify arguments are for running, not for Gradle itself. IIRC, the proposed workarounds was to hand-edit the .gradle file before each run (at least you have the facilities of an editor) or to use properties -P and manipulate it (but you are limited by the command line limitations of your system). -- Philippe Lhoste -- (near) Paris -- France -- http://Phi.Lho.free.fr -- -- -- -- -- -- -- -- -- -- -- -- -- -- --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
In reply to this post by Glen Stampoultzis
Hello Glen,
sorry for the late reply. You can pass properties from the commandLine to your run task by using a bit groovy: You can dynamically add args to the run task: ---------------- run{ if(project.hasProperty("appProp")){ args appProp } } ---------------- this checks if a property named "appProp" is defined. If true, it passes the property to the arg method of the run task. Now you can run your app via gradle from the commandline: ---------- gradle run -PappProp=test ---------- regards René
|
On 08/03/2012 22:26, Rene Groeschke wrote:
> Hello Glen, > sorry for the late reply. You can pass properties from the commandLine to your run task by > using a bit groovy: > You can dynamically add args to the run task: > ---------------- > run{ > if(project.hasProperty("appProp")){ > args appProp > } > } > ---------------- > > this checks if a property named "appProp" is defined. If true, it passes the property to > the arg method of the run task. > Now you can run your app via gradle from the commandline: > > ---------- > gradle run -PappProp=test > ---------- That's the detailed version of what I wrote, but as I said, it isn't very practical if you want several parameters, some being quoted (eg. a path), and so on. I would prefer to have something like: gradle run --someGradleOption -R -o "C:/Foo ark/bar.x" -v 5 for example, where after the -R, Gradle doesn't see the parameters as being for itself but pass them (properly parsed according to the underlying system) to the executed task. -- Philippe Lhoste -- (near) Paris -- France -- http://Phi.Lho.free.fr -- -- -- -- -- -- -- -- -- -- -- -- -- -- --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
Free forum by Nabble | Edit this page |