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

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.debug>${flex.debug}</compiler.debug>
    <compiler.library-path dir="${assets.dir}" append="true">
     <include name="**/*.swc" />
    </compiler.library-path>
                                <locale>locale1</locale>
                                <locale>locale2</locale>
                                <locale>locale3</locale>
   </mxmlc>

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'){
   load-config(filename:'$flexHome/frameworks/flex-config.xml')
   source-path((path-element):'$flexHome/frameworks')
   (compiler.debug): '$flexDebug'
   compiler.library-path(dir:flexAssets append:'true'){
    include(name:swcPattern)
   }
   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’

^

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.debug"($flexDebug)
"compiler.library-path"(dir: flexAssets, append: true) { ... } // note the comma
locale("locale1")
...

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

1 Like

That worked, I really appreciate the help.