Developing with Flexmojos | Maven: The Complete Reference
Developing with Flexmojos
13.1. Introduction
This chapter provides an overview of the Flexmojos project for people interested in using Maven to develop Flex applications and libraries.
13.2. Configuring Build Environment for Flexmojos
13.2.1. Referencing a Repository with the Flex Framework
To setup your Maven environment for Flexmojos, you have two options: you can reference the Sonatype Flexmojos repository directly in a pom.xml, or you can install Nexus and add the Sonatype Flexmojos repository as a proxy repository in your own repository manager. While the most straightforward option is to reference the repository directly, downloading and installing Nexus will give you the control and flexibility you need to cache and manage artifacts generated by your own build.13.2.2. Configure a Flexmojos Proxy Repository in Nexus
Once Nexus is installed and started, complete the following steps to add a proxy repository for the Sonatype public repository. To add a new proxy repository:- Click on the Repositories link under Views/Repositories in the Nexus menu on the left-hand side of the Nexus user interface.
- Click on Repositories to load the Repositories panel.
- In the Repositories panel, click on the Add.. button and select Proxy Repository.
13.2.3. Configuring Environment to Support Flex Unit Tests Flexmojos expects to be able to launch the stand-alone Flash Player to execute unit tests. In order for this to work, you will need to add the stand-alone Flash Player to your PATH, or you will need to pass the location of the Flash Player executable to your build using the
-DflashPlayer.commandoptions.13.2.4. Adding FlexMojos to Your Maven Settings' Plugin Groups
If you need to run FlexMojos goals from the command-line, it will be more convenient if you add the Sonatype Plugin groups to your Maven Settings. To do this, open up ~/.m2/settings.xml and add the following plugin groups:
<pluginGroups>
<pluginGroup>com.sonatype.maven.plugins</pluginGroup>
<pluginGroup>org.sonatype.plugins</pluginGroup>
</pluginGroups>
13.3. Creating a Flex Mojos Project from an Archetype
Flexmojos has a set of archetypes which can be used to quickly create a new Flex project. The following archetypes are all in the org.sonatype.flexmojos group with a version of ${flexmojos.version}:
- flexmojos-archetypes-library: Creates a simple Flex Library project which produces a SWC
- flexmojos-archetypes-application: Creates a simple Flex Application with produces a SWF
- flexmojos-archetypes-modular-webapp: Creates a Multimodule project which consists of a project that produces a SWC which is consumed by a project which produces a SWF that is ultimately presented in a project that generates a WAR
13.3.1. Creating a Flex Library
To create a Flex Library Project, execute the following command:
$ mvn archetype:generate \
-DarchetypeRepository=http://repository.sonatype.org/content/groups/public\
-DarchetypeGroupId=org.sonatype.flexmojos \
-DarchetypeArtifactId=flexmojos-archetypes-library \
-DarchetypeVersion=${flexmojos.version}
13.3.2. Creating a Flex Application
To create a Flex application from a Maven archetype, execute the following command:
$ mvn archetype:generate \
-DarchetypeRepository=http://repository.sonatype.org/content/groups/public\
-DarchetypeGroupId=org.sonatype.flexmojos \
-DarchetypeArtifactId=flexmojos-archetypes-application \
-DarchetypeVersion=${flexmojos.version}
13.3.3. Creating a Multi-module Project: Web Application with a Flex
To create a multi-module project consisting of a Flex Library project referenced by a Flex Application, referenced by a Web Application:
$ mvn archetype:generate \
-DarchetypeRepository=http://repository.sonatype.org/content/groups/public\
-DarchetypeGroupId=org.sonatype.flexmojos \
-DarchetypeArtifactId=flexmojos-archetypes-modular-webapp \
-DarchetypeVersion=${flexmojos.version}
13.4. The FlexMojos Lifecycle
The FlexMojos Maven plugin customizes the lifecycle based on the packaging. If your project has a packaging of type swc or swf, the FlexMojos plugin with execute a customized lifecycle if your plugin configuration sets the extensions to true.
13.5. FlexMojos Plugin Goals
The FlexMojos Maven Plugin contains several goals:
- flexmojos:asdoc: Generates documentation for Actionscript source files
- flexmojos:compile-swc: Compiles Flex source (Actionscript and MXML) into a SWC library for use in Flex or AIR applications
- flexmojos:copy-flex-resources: Copies Flex resources into a web application project
13.6. FlexMojos Plugin Reports
The FlexMojos Maven Plugin contains the flexmojos:asdoc-report which generates documentation for Actionscript sources as a report that can be included in a Maven site.
13.7. Developing and Customizing Flexmojos
Flexmojos is an open-source project hosted on the Sonatype Forge, and the source code for Flexmojos can be accessed within their repository.