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

Grails:如何从BuildConfig.groovy知道正在执行哪个命令,grails,build,command,Grails,Build,Command,是否可以从BuildConfig.groovy文件中知道正在执行哪个命令,以便根据该命令更改构建配置?例如,如果“模式导出”,那么不包括“Foo”库等等? 我正在使用Eclipse,并且正在从Eclipse运行rails cmd 编辑:在试用了Shashank解决方案之后,我添加了关于我正在使用Eclipse的细节 通过打印'sun.java.command'属性,我认为我的Eclipse安装(Indigo Service Release 2+Grails IDE 3.5插件)正在重写启动到的命

是否可以从BuildConfig.groovy文件中知道正在执行哪个命令,以便根据该命令更改构建配置?例如,如果“模式导出”,那么不包括“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
}
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
或者举个例子:

compile (":some-plugin:2.3") {
    if (command.contains("export-schema")) {
        excludes "foo"
    }
}
该属性将为您提供如下输出:

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
}
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

我尝试了您的解决方案,但在eclipse中,该命令似乎与预期的有所不同。事实上,没有“模式导出”的痕迹,即原始命令。如果在eclipse之外,我认为您的解决方案是正确的。是的,当我运行终端时,这个解决方案对我来说很好。您仍然可以使用eclipse来实现这一点。只需打印所有系统属性并搜索您的命令,然后查看保存正在执行的命令的系统属性。我尝试了,但所有属性似乎都不包含命令的名称command@Andrea我在GGTS中尝试过这个(与eclipse相同)我得到了指定的命令值,所以可能是我的eclipse或grails插件安装的结果。