Flex Project version and buildnumber

I wanted to associate version and build information with every compilation of a Flex project. Such information is useful when deploying to different staging environments (e.g. are you sure you uploaded the correct SWF ?) and helps tracking feedback (e.g. bugs) from users using a particular build.

First, I added a simple resource version.xml to store version and build info:

<?xml version='1.0' encoding='UTF-8'?/>
<version name='0.1' build='124'/>

Then I defined a component Version.mxml to show that information in plain text:

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"  horizontalGap="0">
<mx:XML id="version" source="/version.xml" />
<mx:Label text="Version:"/>
<mx:Label text="{version.@name}"/>
<mx:Label text="Build:"/>
<mx:Label text="{version.@build}"/>

So far nothing to get exited about. What is left to do is get this information updated automatically for every Flex compilation (no I am not using Ant or Maven for Flex at this time).

I am using Eclipse for all my Java, Ruby and Flex projects. Eclipse uses Builders to fire all kinds of project tasks. So I added a custom builder (see Project Properties) that runs a simple Ruby script (as an External Program) that reads, changes and writes the version.xml resource. Make sure this builder is the first one to run.


# This script updates the version.xml file by incrementing the build number

require 'rexml/document'
file = File.new("version.xml")
root = REXML::Document.new(file).root
root.attributes['build'] = root.attributes['build'].to_i + 1
File.open("version.xml",'w') do |f| f << root.parent end
comments powered by Disqus