Trying to create a grails ant task that has other environments besides prod for the war task.
i've tried
<target name="war" depends="-init-grails" description="--> Creates a WAR of a Grails application">
<grails script="War" args="grails.env=${env} ${war.filename}"/>
</target>
and
<target name="war" depends="-init-grails" description="--> Creates a WAR of a Grails application">
<grails script="War" args="-Dgrails.env=${env} ${war.filename}"/>
</target>
Neither of these tw开发者_运维技巧o 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>
you might want to look at grails scripting to solve your problem
http://www.grails.org/Command+Line+Scripting
it has wrapped ANT so you can utilize ant tasks inside the scripts and I believe you have access to the environment and lots of other "groovy" stuff
i think you can also do this if you are set on using ant, although I havent tried it with grails scripts
<exec executable="grails" failonerror="true">
<arg line='-c war grails.env=${env} ${war.filename}' />
</exec>
if you go in your project directory and run "grails --integrate-with -ant" it will create a build.xml which will automatically use ivy to download dependencies, and grails, and creates the macro def for you.
You can use the build.xml as a starting point for your project
精彩评论