Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

Thursday, May 6, 2010

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

It's been a week since I originally posted about Building Flex 4 AIR apps with Maven. This is just a quick note that I made an update to the code listings. The update in question is pretty minor but just in case you copied code from the previous post and it stopped working all of a sudden this change might be the culprit.

The change is simply that a change was made in the latest 3.7-SNAPSHOT of the plugin that changes what was flexbuilderCompatibility to flexBuilderCompatibility. Notice the capital "B" in flexBuilder:


<flexBuilderCompatibility>true</flexBuilderCompatibility>

One other thing to note is that I posted some of this same information on the flex-mojos wiki.

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>
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


<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.


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