grails ant 任务,设置不同的环境 [英] grails ant task, set different envrionment
本文介绍了grails ant 任务,设置不同的环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试创建一个 grails ant 任务,除了用于战争任务的 prod 之外,还有其他环境.
Trying to create a grails ant task that has other environments besides prod for the war task.
我试过了
<target name="war" depends="-init-grails" description="--> Creates a WAR of a Grails application">
<grails script="War" args="grails.env=${env} ${war.filename}"/>
</target>
和
<target name="war" depends="-init-grails" description="--> Creates a WAR of a Grails application">
<grails script="War" args="-Dgrails.env=${env} ${war.filename}"/>
</target>
这两个都不起作用,总是只运行生产环境.请注意,我还对 ${env} 进行了硬编码,因此并不是缺少它
Neither of these two work and always just run the production env. Note that I've also hard coded ${env} so it's not that it's missing
推荐答案
我为此使用了一个宏定义:
I use a macrodef for this:
<property environment='env'/>
<property name='grails.home' value='${env.GRAILS_HOME}' />
<condition property='grails' value='grails.bat'>
<os family='windows'/>
</condition>
<property name='grails' value='grails' />
<macrodef name='grails'>
<attribute name='action' />
<attribute name='environment' default='dev' />
<element name='preargs' optional='true' />
<element name='args' optional='true' />
<sequential>
<exec executable='${grails}' failonerror='true'>
<preargs />
<arg value='@{environment}'/>
<arg value='@{action}'/>
<args />
</exec>
</sequential>
</macrodef>
您可以执行简单的命令:
You can execute simple commands:
<grails action='clean' />
或更复杂的任务,比如你的战争任务:
or more complex ones like your war task:
<grails action='war' environment='${env}'>
<args>
<arg value="${war.filename}" />
</args>
</grails>
这篇关于grails ant 任务,设置不同的环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文