Gradle application plugin question

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Gradle application plugin question

Glen Stampoultzis
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
Reply | Threaded
Open this post in threaded view
|

Re: Gradle application plugin question

Rene Groeschke
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é
6. März 2012 01:54
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


Reply | Threaded
Open this post in threaded view
|

Re: Gradle application plugin question

Glen Stampoultzis
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:
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é
6. März 2012 01:54
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



Reply | Threaded
Open this post in threaded view
|

Re: Gradle application plugin question

Philippe Lhoste
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


Reply | Threaded
Open this post in threaded view
|

Re: Gradle application plugin question

Rene Groeschke
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é

7. März 2012 04:04
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




6. März 2012 09:09
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é

6. März 2012 01:54
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


Reply | Threaded
Open this post in threaded view
|

Re: Gradle application plugin question

Philippe Lhoste
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