Maven + Flex

I wish this were a post explaining how to use Maven with Flex. I’m afraid this is rather documenting the journey. If you’re lucky (and I am lucky too) I’ll have an additional post or two explaining how I got this to work.

Update: After getting some help from Velo (the very helpful author of the flex-mojos project) I finally got things working. Only THEN did I come across this blog entry that outlines, well, pretty much everything I was looking for. Thanks Ryan Knight!

I’m a big fan of using Ant to build my Flex projects. I have a pretty standard way to setting up my projects now. I’m a copy ‘n paster and when I start a project I drop in my ‘standard’ build.xml file. This puppy will build a .swf (or a .swc with just a few changes), will inject the SVN revision number into the .swf, can document (ASDoc style) the project and will package everything up into .zip files. So now I’m comfortable with it. It’s easy it’s fast. I understand how things work.

But I’m working on a project that is mostly Java. The collection of projects are managed by Maven. And now I’m trying to integrate a couple of Flash projects and I’m kinda lost. The mindset of Maven seems to be quite different than Ant. From what I’m reading online people who like Maven REALLY like Maven. It’s almost a religious thing. And while I can subscribe to the benefits the difficulties I’m having trying to understand everything is frustrating. While Ant is “procedural” (“it’s not a scripting language!”) Maven seems to be “model based”. I guess? It’s driven by POM files (Project Object Model). And (from what I understand) the POM files outline the details of the project and then the commands you execute (build, package, document, even create eclipse project settings) use the properties outlined in the POM file to execute. You don’t outline WHAT you want to do (like you do in Ant) you just outline the details of the project essentially defining HOW.
Read more

Automated Revisioning (SVN + Ant + Flex)

Tell me if this has happened to you: Your client wants a simple change to your awesome Flex application. You rock it out and deliver a new .swf with the piece of cake change. But nothing is different for them! The problem is still there! You spend the next four hours trying to figure out why the fix works for you and not for them. Only to find out that the file was put on the wrong server. Or that their .swf was still cached. Or any number of reasons as to why the newest build isn’t seen. Wouldn’t it be great to know that the .swf they’re seeing is the .swf they’re supposed to see? Maybe some number in there that shows what revision their .swf is?

There are some great tools that handle that stuff for us. CruiseControll is a great example. But usually I don’t need a tool as powerful as all that. And besides, most of that stuff is written for those Java people. I already use Ant to package up my builds for delivery. And I always keep all of my projects in some SVN repo or another. Wouldn’t it be great if I could just stick the SVN revision number somewhere in the application code automatically?

Well I can. And I do. And it’s incredibly handy. This is how it works. (BTW my work environment is Windows, but you should be able to do all of this on Linux/Mac as well)

You can grab these Ant Project Files to get you started as well. There are plenty of comments inside.
Read more

A Flex-able Life with my Ant

I’ve been using Ant in my developer work-flow for a while now. It’s always been a very helpful tool to make sure that everything comes together. Back in my AS2 days Ant was a fantastic tool to help me develop with the open source AS2 compiler MTASC and family. I was able to setup what I wanted to happen, how I wanted it to build and it would happen every time. Documentation would automatically get created, my assets would get rolled into my .swfs just like I liked and my projects would build like lightning! (At least compared to the uber-slow Flash 8 IDE compiler which I avoided whenever I could). Zips for distribution/testing would get packaged up every Friday afternoon and my co-workers knew exactly how to build the project and put it together; just run the Ant script. No more “open these four .fla files and compile them, then copy those .swf files into this folder with those .flv files and zip it up and send it to testing”. I was probably one of the few Flashers who fell in love with this tool. Even using the Flash IDE in your workflow and not using the tool for compilation at all, Ant can really help with keeping assets organized and clean.

But now I use Flex, and I’m never looking back. The command-line compiler is not only supported but created by Adobe so we don’t have to worry about MTASC’s different work-flow problems, etc. I can develop in any IDE I want to (FB in Eclipse is still my favorite, but there are certainly other solutions). We can have our cake and eat it too. And I do love my cake.

So how do I use Ant now? Well, there is no doubt that using the compiler in the Flex Builder IDE is faster than running an Ant script in most scenarios. The compiler in the IDE stays in memory and only build what needs to be built. When you run an Ant build you have to completely load the compiler and project into memory every time. The Flex Compiler Shell (fcsh) helps to eliminate this somewhat but that doesn’t easily help Ant out (at least not yet, or that I know of). It can be very helpful if you’re using an alternate development environment however and smacking “F11″ to get a quick debug build isn’t an option for you.

Since a quick “F11 smack” is what I do use most of the time, Ant has taken a bit of a back seat in my work-flow. But even still a little piece of mind is offered by using Ant. I commonly run my builds on a machine other than my development machine (my personal repo server for instance). If it builds there (which is only exactly what is current in the repo, nothing more, nothing less) then it should build everywhere. No more “works for me” excuses. And automatic builds are a GREAT way to leverage the tool. I have worked in an environment where the projects were built on our repo server every time assets were committed (using SVN post-commit hooks). I think having a daily build to push something into a public or semi-public place is a great help to everybody too. Managers no longer have to bug the developers for another build to see how this certain feature is progressing. Weekly builds for clients could happen every Sunday night at midnight so they get a shiny new build every Monday. Of course if you don’t want builds delivered like clockwork, the delivery is still just as easy when you want it done. Run and your done.

But I degress. I’m sure you already love Ant and realize it’s power. You just want to know how to use it with your Flex projects. Well, here comes the magic.

Read more