How to give command line parameters to JavaExec?

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

How to give command line parameters to JavaExec?

Philippe Lhoste
I googled a bit around for the answer, but found no satisfying answer.
Perhaps I just missed something or made wrong searches...

I use simple Gradle scripts to compile and run simple Scala command line
programs. So far, so good.
But I use some command line parameters in the Scala code to change its
behavior (like -t for trace, -v for verbose, etc.).

Currently, I use JavaExec to run the Scala classes:

testName = hasProperty('t') ? t : 'ABC'

task runt(type: JavaExec) {
   // gradle -Pt=Test runt
   description = 'To run the test programs with trace on. Pass the name
as -Pt=Test.'
   main = testName
   classpath = sourceSets.main.runtimeClasspath
   args '-t'
}

As you can see, I use the -P parameter to know which class to run.
I also have run, runt and runv tasks to run the class without
parameters, or with the t or v parameters. It doesn't scale well...

Am I stuck to pass the parameters using -P too, or is there some smart
way to specify them on the command line of Gradle?

(Using Windows for what it is worth, and still Gradle 0.9.2)

--
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: How to give command line parameters to JavaExec?

Philippe Lhoste
On 20/08/2011 16:36, Philippe Lhoste wrote:
> Am I stuck to pass the parameters using -P too, or is there some smart
> way to specify them on the command line of Gradle?

Tried -Pr="t v"
But as I feared, it is then seen as a unique parameter.
I suppose I can write some Groovy (supposing I am able to do that...) to
split the string, while handling parameters with spaces in them, but
this is getting clumsy...

--
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: How to give command line parameters to JavaExec?

Peter Niederwieser
You can use project properties (-P) and/or task rules (http://gradle.org/current/docs/userguide/userguide_single.html#N10DA8). In theory you could also fiddle with gradle.startParameter.taskNames, but I'd only do this as a last resort.

--
Peter Niederwieser
Principal Engineer, Gradleware
http://gradleware.com
Creator, Spock Framework
http://spockframework.org
Twitter: @pniederw

Philippe Lhoste wrote
On 20/08/2011 16:36, Philippe Lhoste wrote:
> Am I stuck to pass the parameters using -P too, or is there some smart
> way to specify them on the command line of Gradle?

Tried -Pr="t v"
But as I feared, it is then seen as a unique parameter.
I suppose I can write some Groovy (supposing I am able to do that...) to
split the string, while handling parameters with spaces in them, but
this is getting clumsy...

--
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: How to give command line parameters to JavaExec?

Philippe Lhoste
On 20/08/2011 18:44, Peter Niederwieser wrote:
> You can use project properties (-P)

Yes, I just tried that, but it is a bit inflexible, I fear. Or perhaps I
must find a creative way of using them...

> and/or task rules
> (http://gradle.org/current/docs/userguide/userguide_single.html#N10DA8). In

Interesting, but still hard to use. Or perhaps I just lacks imagination.
I just found there the application plugin, but apparently it just
provides shortcuts to comm

> theory you could also fiddle with gradle.startParameter.taskNames, but I'd
> only do this as a last resort.

Mmm...

I wonder if Gradle could have some special kind of project properties,
filling an array (or a List, apparenty) with the parameters following
it. Of course, such parameter should be last in the command line.
Something like:

gradle -Pt=someClass run -A tvf -X -o="a dir" "file name with spaces"

But there is an extra difficulty with handling the OS conventions:
Windows accepts only double quotes, Unix-based systems are more
flexible, etc.

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email