<flexBuilderCompatibility>true</flexBuilderCompatibility>
Thursday, May 6, 2010
Building Flex 4 AIR application with flex-mojos (Maven) - Update
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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://
www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://
maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mcgraphix.xd</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<name>my-app Flex</name>
<properties>
<flex.framework.version>4.0.0.14159</flex.framework.version>
<sourceDir>src/main/flex</sourceDir>
</properties>
<packaging>swf</packaging>
<build>
<sourceDirectory>src/main/flex</sourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.7-SNAPSHOT</version>
<extensions>true</extensions>
<dependencies>
<dependency>
<groupId>com.adobe.flex</groupId>
<artifactId>compiler</artifactId>
<version>${flex.framework.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.compiler</groupId>
<artifactId>adt</artifactId>
<version>${flex.framework.version}</version>
</dependency>
</dependencies>
<configuration>
<sourceFile>AirTest.mxml</sourceFile>
<flexbuilderCompatibility>true</flexbuilderCompatibility>
<descriptorTemplate>${basedir}/src/main/flex/AirTest-app.xml</descriptorTemplate>
<keystore>${basedir}/cert.p12</keystore>
<storepass>secret</storepass>
<includeFileSets>
<fileSet>
<directory>src/main/resources/embedded</directory>
<includes>
<include>*.*</include>
</includes>
</fileSet>
</includeFileSets>
</configuration>
<executions>
<execution>
<goals>
<goal>sign-air</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>air-framework</artifactId>
<version>${flex.framework.version}</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
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
app.xml]</content>
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:
<content>my-app-1.0-SNAPSHOT.swf</content>
<flexBuilderCompatibility>true</flexBuilderCompatibility>
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}.
<version>${version}</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.