NOTE - This article is no longer relevant. The latest flex ant tasks support including recursive source directories. See comments posted by readers.
Using Flex Ant Tasks with the Flex SDK is a great way to do automated builds for your Flex Projects. Flex Tasks provide Ant task interfaces for compiling both applications (*.swf) and libraries (*.swc).
<compc> Requires Manually Specified Class Names!
The compc task comes up a little short in that you have to specify ALL of your classes you want in your component library like this
<compc
output=“MySWC.swc”
include-classes=“my.package.MyClass1 my.package.MyClass2″>
<source-path path-element=“${basedir}”/>
</compc>
Most of the time, I find myself wanting *all* of my actionscript classes in the component library SWC file. More importantly, I do not want to have to update an Ant target if I add classes to the library.
You might ask ‘well why not generate a fileset and pass it to the include-source attribute?’ Great idea except the compc task doesn’t support include-source. Boo!
*Sigh* - it would be nice if I could just have my classes auto-generated for this compilation task!
Use Ant to Auto-generate Class Names
After some googling, I found that there really isn’t a built-in mechanism for doing this. Below you’ll find a sample target I put together that auto-generates the class names to pass to compc based on the actionscript filenames it compiles.
<target name=“swc”>
<fileset id=“sources” dir=“com”>
<include name=“**/*.as”/>
</fileset>
<pathconvert property=“classes” pathsep=” “ refid=“sources”>
<chainedmapper>
<globmapper from=“${basedir}/*” to=“*”/>
<mapper type=“package” from=“*.as” to=“*”/>
</chainedmapper>
</pathconvert>
<echo message=“classes is set to = ${classes}”/>
<compc output=“MySWC.swc” include-classes=“${classes}”>
<source-path path-element=“${basedir}”/>
</compc>
</target>
The target uses the fileset, pathconvert and mapper tasks available in Ant.
- It finds all of the actionscript source files with a fileset.
- It converts the list of files to a single line with each file separated by a space
- Using mappers, it then converts the filename to a package/class name notation
Note that your project should define the ‘basedir’ property in the initial ‘project’ tag.
By using Ant to autogenerate classnames from actionscript filenames, my library build files are alot easier to maintain. Hopefully it’ll do the same for you!
January 4, 2008 at 12:04 am
[...] from this blog - compiler.library-path. include-classes is another headache that Straylink offers a solution. index.template.html is again poorly documented by Adobe, but Renaun Erickson’s posting [...]
March 20, 2008 at 9:51 pm
I was able to build all the MXML and AS files without putting everything into the classes variable as you have done.
I think its the include-sources which does the full recursive include.
Also I use fcsh to build my main MXML because the ANT build is too slow!!!!
March 20, 2008 at 9:52 pm
Ahh it stripped out all my code…….
either include-sources or source-path allowed me to do full recursive include for the swc compile.
May 26, 2008 at 8:35 pm
A quick note - you are using the ‘path-element’ attribute… which is what you would expect from the docs - but is incorrect. The correct companion attribute for include-source is ‘dir’ and would look like:
<include-source dir=”.”/> –or– <is dir=”.”/>
Make sure you are using the latest and greatest version of Flex Ant Tasks and you should be good to go.
http://download.macromedia.com/pub/labs/flex_ant_tasks/flex_ant_tasks_022607.zip
July 16, 2008 at 4:29 pm
wonderful. exactly what i was looking for!