Wednesday, April 28, 2010

Building Flex 4 AIR application with flex-mojos (Maven)

After spending a number of hours trying to get my Flex 4 AIR application to successfully build with the maven flex-mojos plugin, I was finally able to create a pom.xml file that worked. There are a few gotchas to deal with which are detailed below. First of all here is the working pom.xml

<project xmlns="" xmlns:xsi="http://" xsi:schemaLocation="http://">
<name>my-app Flex</name>

Also notice that includeFiles and includeFileSets configuration parameters are both set. Although the documentation says they are not required, leaving them out causes an exception to be thrown from the sign-air goal. This has been fixed in the latest snapshot.

Also note that it seems to only be possible to include files that are located within the src/main/resources directory.

Also, one other thing to note is that the flex-mojos plugin uses the application descriptor xml file as configured in the descriptorTemplate node. However, there is one change that I had to make in order for the plugin to work. Normally, FlashBuilder updates the descriptor template to specify the name of the SWF in the <content/> node:

<content>[This value will be overwritten by Flex Builder in the output

In order for the sign-air goal to work, I had to manually update that node with the correct value. In my case it needed to be:

This change breaks FlashBuilder but there are two solutions. One would be to just make a duplicate version of the descriptor that you use with flex-mojos and one with FlashBuilder. However, you would need to manually keep them up to date if you change the version number. The other option would be to dynamically make a copy and then update that node as needed. This would theoretically allow you to automatically sync the version number with the version specified in the pom. I haven't figured this part out yet, but I will update this post with my progress. This has been fixed. You can specify the flexBuilderCompatibility parameter to let the plugin manage this automatically


UPDATE: You can also use the special ${output} token in the application descriptor as the value of the content tag which will allow the plugin to set the name of the swf into the descriptor automatically. With this approach, you don't need to set the flexCompatibility paremeter. However, that still breaks Flash Builder's Export Release Build function.

The last step if desired is to let the plugin manage the version number in the application descriptor. This can be done by setting the version node with ${version}.


This doesn't break Flash Builder, however if you use the Export Release Build the version number will be "${version}".

I will bundle everything up and post here shortly.

Also, I have posted some of my findings to the Flex-mojos Google Group.


Unknown said...

air-framework and flex-framework are basically the same dependency. But the first includes airglobal+airframework and the second playerglobal.

So there is no point on adding flex-framework then exclude player global.....


Rob McKeown said...

I will fix that. Thanks for the info... and your answers on the google group too.

Unknown said...

Nice, if you like, you can add that as air usage instructions on wiki (it is public editable, so you can add that)

So other users will more likely find it, you get the credit and flexmojos more documentation. =D


Rob McKeown said...

Sure, I will post it to the wiki tomorrow. Thanks again.

Anonymous said...

There is an other interresting article about air and maven on piaction blog with code exemple:

You can find it here (but in french) :

Strangepork said...

> I will bundle everything up and post here shortly.

Hey I would love to download this bundle! ;-)

Rob McKeown said...

@strangepork - You should be able to find everything you need from the flex-mojos wiki at

I posted all the example files there.

Nabeel Ahmad said...

I am trying to migrate my maven project from flex 3 to flex 4. I have tried a lot of configurations and SDK versions. If for example I spceify...


My IDE recognizes this version but somehow I cannot download the required version. After compiling my pom.xml I get this message

1) com.adobe.flex:compiler:pom:
Path to dependency:
1) org.sonatype.flexmojos:flexmojos-maven-plugin:maven-plugin:3.6.1
2) com.adobe.flex:compiler:pom:

Rob McKeown said...

It sounds like the repositories you are downloading from don't have the new versions deployed. Are you using your own hosted repository?

Anonymous said...

Your example doesn't work anymore can you please update it

Unknown said...

Thanks for the article. Based on this I have created an example porject which uses the newest flexmojo and flex versions. The source is managed on /