Calling grails commands from grails events?
I need to call a plugin with arguments from a grails event script. How do I do this?
Specifically, I'm trying to hook into eventCompile
to call generate-dto --all
, sending y
to STDIN.开发者_开发技巧
The easiest (and probably slowest) way to do it is to invoke grails in an event handler. This is a bit tricky, since generate-dto
generates a compile event, but you can make it conditional on a system property. A second problem is the required input. By convention, grails scripts are all supposed to accept --non-interactive
and not prompt the user, but the dto plugin seems to not follow this. A workaround for Posix systems like Linux or MacOS X is to pipe in the yes
command as the grails input.
Here's how I got it working:
// scripts/_Events.groovy
eventCompileStart = { args ->
if (Boolean.valueOf(System.getProperty('in.generate', "false"))) {
// skip
} else {
['bash', '-c', 'yes | grails -Din.generate=true generate-dto --all'].execute()
}
}
Try running whole compilation with --non-interactive argument
. I tells Grails to skip all the questions and inputs from user eg. if running as job in Jenkins(Hudson). I'm not sure if it will help, but you can try. I used this argument on Hudson to test my app and skip questions about updating plugins.
精彩评论