Friday, April 2, 2010

Mavenizing a Flex Project with multiple artifacts

  I was asked to include a Flex project within the current build process in place (maven2 based). Now, I like maven for many reasons which I'm not going to explain in this entry, however I would like to say a bit about my experience with such a "mavenization" if you will. Most Flex projects I've been involved are developed either directly in Flex Builder (Fb3) and/or compile using an Ant task. Nothing wrong with this approach, however Maven encourages a convention that may not necessarily be embraced in a traditional Flex Application. I hope to explain what I mean by this in the next paragraphs.
  In Flex, a project typically is composed of a default application (an MXML file) and possibly Module components, stylesheets (compiled to SWF files), configuration files, etc. If some of these are within the same project, Fb3 will compile each of them and generate their SWF files properly. The "export" release feature of Fb3 is also a nice feature to do deployments from the IDE. Granted, this feature is nice to have, however following the "maven way", I quickly realized that this "mavenization" process will take longer. This was mostly due to the convention that each maven project aims to build ONE artifact and only one. The project I had was building 15 SWF files (some modules, some css files) as well as 17 XML files. This was simply not acceptable for maven standards.

  As a first pass, I decided to make the project generate a zip file containing each artifact. This would at least ensure one artifact for this project and ensure users to have a corresponding unzip process where each SWF/XML file can be used in a deployment.  Now, the next iteration, I moved from a one maven project style (zip file) to a multiple project (nested) style where each module compiles to and becomes a dependency of the main application project (yet another SWF file).  All this setup was nicely done using Flexmojos integration with Maven. Flexmojos is a nice tool for using Flex within a maven setup, however it has bugs of it own (e.g. depending on the packaging style, Flexmojos may do weird things such as compile Modules to non-swf extensions, or compiling flex code twice, etc). When properly configured, using Flexmojos can be a pleasant experience for most maven setup. 

4 comments:

Unknown said...

Flexmojos is only intended to be used with swf or swc packaging. Anything different from that is expected to not work.

Alberto said...

Yes, I noticed that. Hopefully, I'm not misunderstood. Flexmojos is a nice tool, just simply not the correct tool when there's no time to break down a project into a maven-like project with multiple sub modules.

Unknown said...

Yeah, a maven plugin is usually a bad tool to be using in non-maven style projects...

Maven is all about CoC.... also is Flexmojos.... but once you don't follow the convention you must configure it. And to do that you need to meet the tool a bit deeper.

Alberto said...

agreed