Tuesday, March 3, 2009

Building Flex with Maven and Flex Mojos

I've been getting to know a project that uses Maven and Flex.  The flex portion of the project is currently built using FlexBuilder, and it seemed worth investigating whether or not buildng the Flex using Maven were feasible.


I took a look around at the options, and it seems like the Flex-Mojos project is the one with the most momentum.  It's relatively current, gets updated regularly, and the team seems to be working with Sonatype, well-known in the Maven community.

The Flex Mojos project is still pretty rough in some areas.  In order to get things done, you need to search the blog, the google group, the google code home and the newer wiki and source code repository hosted at Sonatype, as well as the plugin documentation.  I'm hoping that with a little more time, the documentation will start to coalesce in a single location and get better, although sparse documentation is par for the course when it comes to Maven plugins.

With a little work, I was able to get the project to build an SWF file:


<parent>
<groupid>info.flex-mojos</groupid>
<artifactid>flex-super-pom</artifactid>
<version>2.0</version>
</parent>

<repositories>
<repository>
<id>flex-mojos-repository</id>
<url>http://svn.sonatype.org/flexmojos/repository</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
</repositories>

<build>
<plugins>

<plugin>
<groupid>info.flex-mojos</groupid>
<artifactid>flex-compiler-mojo</artifactid>
<configuration>
<sourcefile>CrystalQ2.mxml</sourcefile>
</configuration>
</plugin>

</plugins>
</build>

I also needed to declare a dependency on the SWC library on which the project depended:


<dependencies>
<dependency>
<groupid>com.caucho</groupid>
<artifactid>hessian-flex</artifactid>
<version>3.2.0</version>
<type>swc</type>
</dependency>
</dependencies>
There's still other things I'd need to do to mimic what Flex Builder offers, such as generate an HTML Wrapper and copy assets needed by the final application but not included in the SWF.
That said, I'd say that the basics are already in place and I'm starting to feel comfortable that there are options for putting Flex and Maven together, should you so desire.

2 comments:

Jamie Whitehouse said...

Note that you don't have to inherit from the flex-mojo pom; rather include the equivalent sections in your own pom like source location, etc.

This way you're not at the whim of third-party definitions that could affect the whole build. That and you can then have your own parent pom with organization and deployment information.

Geoffrey Wiseman said...

A couple of their posts imply that the parent pom was the only way to make this work. That seems unlikely to me, and I don't see anything in the parents that I couldn't put in my own, but, until I try it, I won't know for sure whether or not there be tigers.