passing jvm args to forked jvm

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

passing jvm args to forked jvm

Dan Durkin
I was trying to pass a -D arg to tests like

gradle -Dfoo=bar test

which didn't work, as the forked jvm running the tests didn't see this
jvmArg.

I added the following to build.gradle

test{
     jvmArgs '-Dfoo=bar'
}

This works and the forked jvm is passed the jvmArgs.

Question: Can I do this via the command line any way?

I tried:

gradle -Dtest.jvmArgs='-Dfoo=bar'
gradle -Dtest.jvmArgs.foo=bar

Thanks for any pointers.

Dan


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: passing jvm args to forked jvm

Peter Niederwieser
Gradle doesn't yet have a generic feature that allows to configure arbitrary model properties from the command line. But you can do it yourself (per property):

test.jvmArgs System.getProperty("test.jvmArgs", [])

Reply | Threaded
Open this post in threaded view
|

Re: passing jvm args to forked jvm

Dan Durkin
Thanks Peter for clarifying this.

Is this something that is planned or something generally viewed as not
necessary?  Is there another preferred way of doing this?

I was actually playing with the spock IncludeExcludeExtension example in
the https://github.com/spockframework/spock-example project.

I was looking at it trying to evaluate, what it would look like if you
annotated a bunch of tests as @Fast, @Slow or whatever, how easy would
it be to run these.  That's why I was trying the command line args for
the test jvm.

Thanks in advance for any advice.



On 3/21/12 3:52 AM, Peter Niederwieser wrote:

> Gradle doesn't yet have a generic feature that allows to configure arbitrary
> model properties from the command line. But you can do it yourself (per
> property):
>
> test.jvmArgs System.getProperty("test.jvmArgs", [])
>
>
>
> --
> View this message in context: http://gradle.1045684.n5.nabble.com/passing-jvm-args-to-forked-jvm-tp5580908p5582134.html
> Sent from the gradle-user mailing list archive at Nabble.com.
>



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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: passing jvm args to forked jvm

Peter Niederwieser
It's something that's planned but isn't a priority, partly because it isn't easy to implement it well. Today, the best solution is the one I've shown in my previous email. If you just need to configure a couple of properties from the command line, this solution is good enough. If necessary, you could try to come up with a more general solution, for example based on reflection.

In general, the need for configuring many different properties from the command line should be considered a smell. It makes the build less repeatable, less convenient and more error prone. Gradle's philosophy is to keep as much information as possible in its model and under source control.

In case of the test categories, an alternative to passing command line args is to declare multiple test tasks (possibly dynamically in a loop or with Gradle's task rule feature), each of which runs a different set of tests.

As of Spock 0.6, you can't configure categories via system properties alone; you additionally need a spock configuration file. Starting with 0.7, a system property will suffice.

--
Peter Niederwieser
Principal Engineer, Gradleware
http://gradleware.com
Creator, Spock Framework
http://spockframework.org
Twitter: @pniederw
Reply | Threaded
Open this post in threaded view
|

Re: passing jvm args to forked jvm

Justin Ryan
In reply to this post by Dan Durkin
For my own understanding, would this work?

gradle -Ptest.jvmArgs='-Dfoo=bar'

There's no easy way to translate system properties into DSL properties, but -P seems like a straightforward way to access exactly what you want.

On Tue, Mar 20, 2012 at 11:51 AM, Dan Durkin <[hidden email]> wrote:
I was trying to pass a -D arg to tests like

gradle -Dfoo=bar test

which didn't work, as the forked jvm running the tests didn't see this jvmArg.

I added the following to build.gradle

test{
   jvmArgs '-Dfoo=bar'
}

This works and the forked jvm is passed the jvmArgs.

Question: Can I do this via the command line any way?

I tried:

gradle -Dtest.jvmArgs='-Dfoo=bar'
gradle -Dtest.jvmArgs.foo=bar

Thanks for any pointers.

Dan


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

  http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: passing jvm args to forked jvm

Peter Niederwieser
No, it doesn't work. With -P you can (currently) only set project properties but not nested properties. That's essentially what this thread is about, even though the original author tried with -D.

--
Peter Niederwieser
Principal Engineer, Gradleware
http://gradleware.com
Creator, Spock Framework
http://spockframework.org
Twitter: @pniederw
Reply | Threaded
Open this post in threaded view
|

Re: passing jvm args to forked jvm

Dan Durkin
In reply to this post by Peter Niederwieser
Peter,

Thanks for the detailed explanation, this helps quite a bit.

For my purposes, the solution you showed earlier in the thread will be
sufficient, additionally, I'll look at creating some test tasks or using
Gradle's task rule feature, thanks for the suggestion.

Having a simple system property for categories in Spock 0.7 will be great!

Thanks again.

Dan

On 3/21/12 6:25 PM, Peter Niederwieser wrote:

> It's something that's planned but isn't a priority, partly because it isn't
> easy to implement it well. Today, the best solution is the one I've shown in
> my previous email. If you just need to configure a couple of properties from
> the command line, this solution is good enough. If necessary, you could try
> to come up with a more general solution, for example based on reflection.
>
> In general, the need for configuring many different properties from the
> command line should be considered a smell. It makes the build less
> repeatable, less convenient and more error prone. Gradle's philosophy is to
> keep as much information as possible in its model and under source control.
>
> In case of the test categories, an alternative to passing command line args
> is to declare multiple test tasks (possibly dynamically in a loop or with
> Gradle's task rule feature), each of which runs a different set of tests.
>
> As of Spock 0.6, you can't configure categories via system properties alone;
> you additionally need a spock configuration file. Starting with 0.7, a
> system property will suffice.
>
> --
> Peter Niederwieser
> Principal Engineer, Gradleware
> http://gradleware.com
> Creator, Spock Framework
> http://spockframework.org
> Twitter: @pniederw
>
> --
> View this message in context: http://gradle.1045684.n5.nabble.com/passing-jvm-args-to-forked-jvm-tp5580908p5584253.html
> Sent from the gradle-user mailing list archive at Nabble.com.
>



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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: passing jvm args to forked jvm

Philippe Lhoste
In reply to this post by Peter Niederwieser
On 21/03/2012 23:25, Peter Niederwieser wrote:
> In general, the need for configuring many different properties from the
> command line should be considered a smell. It makes the build less
> repeatable, less convenient and more error prone. Gradle's philosophy is to
> keep as much information as possible in its model and under source control.

Well, then, most Unix command line tools are smelly...
Sometime, I make a Java tool which I want to control with the command
line, at least for quickly testing some different settings. I use
Gradle, among other things, because it allows to easily build a
classpath with various libraries, etc. It is still a better alternative
than shell / cmd scripts.
But not being able to easily specify -o xxx.bin or --exportformat=png
(which are still just kind of properties) on the command line is quite
annoying.

I can understand it is low priority as it cannot be a very common case
(but that's the third thread I see, at least (counting mine...)
expressing this need) and because it is hard to take in account the
various ways to quote parameters on various shells, but that's still
annoying.

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


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: passing jvm args to forked jvm

Peter Niederwieser
Setting an arbitrary property in the build's object model (which is only constructed in the build's evaluation phase) is very different from setting a fixed command-line parameter. As I said, the main reason why this feature is not there yet is that it's still unclear how to implement it. Typically, this limitation can be worked around by adding a few lines of code that map system or project properties to the desired model properties. I understand that this is not particularly pleasing, but it gets the job done.

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