Using ant for Flex – a no B.S. guide – Part 3 of 4

This third installment talks about tips and tricks for using ant with version control systems.

Defining external properties for each user

Since not everyone’s machine is the same and letting everyone build a project is a major reason to use ant, it’s good to avoid hard coding paths to files within your build.xml file. As such, I use a lot of <property> tags to set up paths and such. But you also don’t want to have several people constantly editing your build.xml because it could get broken or out of sync. Oh no! What do we do!?

Luckily, ant lets you define a set of properties in an external file. This is a simple text file containing name=value pairs and commented using #. By default, the recommended filename is build.properties. Here’s an example:

build.properties and version control

If you’re working with multiple people, you are probably using a version control system like svn. If you are and you want to avoid people accidentally checking in a build.properties file there are a couple of simple tricks. First, create a copy of build.properties and call it built.properties.template and check that into the repository. Then each user can make a local copy called build.properties. You can also add build.properties to the ignore list for your folder using SVN so that noone will accidentally check it in. Run svn pe svn:ignore and add build.properties to the list. Finally, if you need to make sure that your users have a local copy of build.properties, there’s a task for that!â„¢

Adding SVN tasks

As I work with SVN quite a lot, I found that including SVN in my builds can be quite useful. For example you could:

  • Update your working copy when doing a clean build.
  • Check in a release build automatically.
  • Export your source code without those pesky .svn files to be included in a zip file.
  • Include the revision number of the working copy as a constant definition in the code using conditional compiliation.

To do this, you’ll need to first download the SVN tasks for ant. They can be found on the Tigris.org website. Please note, that these tasks are a part of SubClipse, which is a free interface for working with Subversion from within Eclipse. I don’t know if the tasks will work without subclispe, but if you haven’t used it, I’d definitely recommend trying it out anyway. By the way, if you use CVS, there are already tasks included in ant. Once they’re downloaded, add the task .jars to the libs/ant folder in your project. You’ll need to use another <typedef> tag in your build script to get these to work. Here’s an example snippet that simply runs an update on the working copy. You can see all the available commands in the svnant documentation.

That’s it for part 3. In Part 4, I’ll talk about setting up a builder for your ant file in FlashBuilder.

About Mims H Wright

http://dispatchevent.org/wp-content/avatars/animemims.gif
This entry was posted in Flex, Tips, Tricks, and Hacks, Tutorial and tagged , , , , . Bookmark the permalink.

One Response to Using ant for Flex – a no B.S. guide – Part 3 of 4

  1. Theo Denovan says:

    Thanks for a great tutorial series!

    It’s great to see someone documenting what, as you pointed out, seems to be a vastly under-documented tool in the context of flex.

    The points about external configuration files and source control have been particularly helpful. If you use Cairngorm the Cairgen templates are extremely useful.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>