How to Convert Dot and Dash separated ANT task arguments into Gradle arguments for MXML task

(Brian Hyder) #1

I am trying to convert my ant builds to gradle. We currently use flexTasks to compile the flex application through ant. I want to define an ant task in Gradle however it doesn’t seem to like the fact that some of the inner elements of the mxml task are like the following:

<mxmlc fork="true" file="${flex.src.dir}/com/@{name}.mxml" output="${work.dir}/com/@{name}.swf">
    <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
    <source-path path-element="${flex.src.dir}"/>
    <source-path path-element="${FLEX_HOME}/frameworks"/>
    <compiler.library-path dir="${assets.dir}" append="true">
     <include name="**/*.swc" />

When I try to convert this into an ant task this inner xml is in the closure as:

ant.mxmlc(fork:'true', file:'$flexSource/MainApplication.mxml', output:'$flexWorkDir/MainApplication.swf'){
   (compiler.debug): '$flexDebug'
   compiler.library-path(dir:flexAssets append:'true'){
   locale: 'locale1'
   locale: 'locale2'
   locale: 'locale3'

When I try to build I get the error:

  • What went wrong: Could not compile build file ‘C:\code\artim\artim-ui-cust\build.gradle’. > startup failed:

build file ‘C:\code\artim\artim-ui-cust\build.gradle’: 31: expecting ‘}’, found ‘:’ @ line 31, column 20.

(compiler.debug): ‘$flexDebug’


(Peter Niederwieser) #2

There are several problems with your syntax. In Groovy/Gradle, colons are only used in named method parameters (and maps), not on the outer level. Hyphens and dots cannot occur in regular method names; in such cases, a String literal has to be used. Try this:

"load-config"(filename: '$flexHome/frameworks/flex-config.xml')
"compiler.library-path"(dir: flexAssets, append: true) { ... } // note the comma

If variables like ‘flexHome’ and ‘flexDebug’ are to be resolved by Groovy/Gradle, you have to use double-quoted Strings.

(Brian Hyder) #3

That worked, I really appreciate the help.