Grails:如何知道正在执行哪个命令,来自 BuildConfig.groovy

Grails: How to know which command is being executed, from BuildConfig.groovy

是否可以从 BuildConfig.groovy 文件中知道正在执行哪个命令,以便根据命令更改构建配置?例如,如果 'schema-export' 那么不包括 'Foo' 库等等? 我正在使用 Eclipse,我是来自 Eclipse 的 运行 rails cmd。

编辑:在试用 Shashank 解决方案后,我添加了有关我正在使用 Eclipse 的详细信息。

通过打印 'sun.java.command' 属性 我认为我的 Eclipse 安装(Indigo Service Release 2 + Grails IDE 3.5 插件)正在重写启动的命令

org.codehaus.groovy.grails.cli.support.GrailsStarter --main org.grails.ide.eclipse.longrunning.process.GrailsProcess --conf Y:\grails-2.4.4\/conf/groovy-starter.conf --classpath /C:/Program Files/eclipse/configuration/org.eclipse.osgi/bundles/1764/1/.cp/;/C:/Program Files/eclipse/configuration/org.eclipse.osgi/bundles/1766/1/.cp/ --is14

我看过了,是的,绝对有可能。

在BuildConfig的任何地方,你都可以这样写:

String command = System.getProperty("sun.java.command")

if (command.contains("run-app")) {
    compile (":hibernate:3.6.10.18")  // example to install hibernate while running the app
} else if (command.contains("test-app")) {
    compile (":hibernate:3.6.10.14")  // some other version for test cases
}

或者你的例子:

compile (":some-plugin:2.3") {
    if (command.contains("export-schema")) {
        excludes "foo"
    }
}

属性 会给你这样的输出:

org.codehaus.groovy.grails.cli.support.GrailsStarter --main org.codehaus.groovy.grails.cli.GrailsScriptRunner --conf /home/user/.gvm/grails/current/conf/groovy-starter.conf --classpath   --offline run-app