Automatically version a Flex application with Maven

Today I had an issue debugging a Flex application.


Some of my changes were not built correctly and I had a hard time debugging and checking whether the version of the swf I had deployed is the same with the latest version of my swf file.


I wanted to have an embedded code into the swf and display it into a label, at runtime. Browsing the internet initially, I’ve found some solutions using Python and Ruby.  Having my build in maven, I decided to see what is provided by Flex, FlexMojos and Maven in order to facilitate that.

Analyzing the mxmlc compiler arguments I have found that I can define custom parameters into the compiler and read them from actionscript code. So I have defined a BUILD::buildNumber compiler variable:


In the Main.mxml application I’ve added:

		* specified through the flex compiler arguments like: 
		* -define+=BUILD::buildNumber,"'1.0.0'"
		private static var buildNumber:String = BUILD::buildNumber;
	right="0" top="0"
	text="{buildNumber}" />

Next, I had to change the compiler parameter for each build, automatically. Using Hudson as my Continuous Integration server, things got very simple. When a Hudson job executes, it sets some environment variables that can be used in build scripts. Among those variables there is BUILD_NUMBER.


The output of this, for a buildNumber 173 and a project version 1.0-SNAPSHOT is:


The next thing I need to achieve, is to trick the browser’s cache, using this buildNumber, appending it at the end of the request for Main.swf, to end up automatically with a request like:

My next post covers this.


Sorry, the comment form is closed at this time.

Comments RSS Feed