开发者

How to invoke non default target in grails gant script

I have a gant script A 开发者_StackOverflowwith two targets

t1 - default target t2 - another target

Even when I run

grails A t2

the default target is run? How can I run the non-default target? I have tried grails A --target='t2' etc. but doesn't work.


I'm not sure if there's a proper way to do it, but you can write a second script ("T2.groovy") that loads this one and sets that target as its default, e.g.

includeTargets << new File("path/to/YourScript")

setDefaultTarget("t2")


A tweak to argsParsing approach is to run through elements from the argsMap and iteratively depend on them. So you could call your script something like:

grails myScript do-this do-that do-the-other

scriptName = 'myScriptName'    
includeTargets << grailsScript("_GrailsArgParsing")

snip

target(main: "Default Target") {
  depends(parseArguments)
  if(argsMap?.size() == 0) {
    depends(scriptError)
  }
  argsMap.each() {
    if (it.value) {
       println "${scriptName} building: ${it.value}"
       depends(it.value)
    }
    else {
       depends(scriptError)
    }
  }
}

snip

target(help: "Print a help message") {
   println "${scriptName}: possible targets are..."
   println "\thelp - print this help message" 
}   

target(scriptError: "Print an error and die") {
   println "${scriptName}: Please specify at least one target name"
   depends(help) 
   exit 1   
}


This is another approach that I took

includeTargets << grailsScript("_GrailsArgParsing")

snip

target(main: "a script") { 
    if(!argsMap.target)
        throw new IllegalArgumentException("please specify target name with --target option")

   depends(argsMap.target)
}

setDefaultTarget(main)

You run the script with a parameter. That parameter is the name of the method to run :) That method then get's executed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜