Gant script command line arguments

There seems to be a non-obvious difference in how grails script parameters are handled in the dos command line vs the grails command line.


The Grails run-script command can run multiple scripts. But I do not see a way to pass arguments to those scripts. For eg:

c:>grails dev run-script MyScript.groovy param1 param2 param3

didn’t seem to work.

I wrote a small gant script to overcome this, very similar to the RunScript to pass the arguments. The argument parser is now based on CommandLineParser (since Grails 2.0.3) and is available in argsMap.

I tried the following cmd line:

c:>grails dev my-script --year=2000 --month=12 --date=31
assert argsMap == [year:2000, month:12, date:31] //FAIL
assert argsMap == [year:true, month:true, date:true, params:[12,2000,31]] //PASS

Obviously this is not what I wanted! I wanted the first assert to pass. After a bit of poking around, I ran the same script but within the grails cmd line environment, like this:

grails>my-script --year=2000 --month=12 --date=31
assert argsMap == [year:2000, month:12, date:31] //PASS

So there was a indeed difference between running the script from within the grails environment and running the grails command from dos prompt. I prefer the latter because thats I what I would do executing a build plan in Bamboo.


So the fix was to add double quotes to each parameter:

c:>grails dev my-script "--year=2000" "--month=12" "--date=31"
assert == argsMap: [year:2000, month:12, date:31]

2 Responses to Gant script command line arguments

  1. mrpaulwoods says:

    Thanks. I didn’t know to double-quote the arguments in Grails. This solves my issues with the resources plugin.


  2. vasya10 says:

    @mrpaulwoods, glad it helped!


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: