ActionScript Build Automation with Maven and FlexMojos

For the past few days I’ve had to deal with adding build automation to an old ActionScript project. While there are several ways to do it, in this post I will cover ActionScript build automation with Maven and FlexMojos, and for unit testing we’ll use FlexUnit.

You can find additional information directly from the maintainer (Christofer Dutz) here (primary) and here (old), or you can go to the Apache Flex mailing list and ask for help there.

Right from the start I have to underline that doing this is a PITA as the support and documentation are lacking and you end up reading many different guides before getting it done. Furthermore, I will only cover the basics (until you get it to compile) and for additional information you will either have to do some digging or wait for me to publish in a future post.

I will assume you are familiar with Maven and that you have it already installed.

The first thing is to create an empty project which will be developed in the future.

mvn archetype:generate \
-DarchetypeRepository=https://oss.sonatype.org/content/repositories/snapshots/ \
-DarchetypeGroupId=net.flexmojos.oss \
-DarchetypeArtifactId=flexmojos-archetypes-library \
-DarchetypeVersion=7.1.0-SNAPSHOT

And now we have a basic pom.xml, however if we issue

mvn install

it will fail to build because of missing dependencies.

Next we setup Apache Flex. We will download flex-utitilies which provides mavenizer, a utility to download and install Apache Flex, Adobe Flash, Adobe Air and Fonts.

git clone https://git-wip-us.apache.org/repos/asf/flex-utilities.git flex-utilities
cd flex-utilities/mavenizer
git checkout develop
mvn install

There are two ways you can achieve the next steps. First we can download and the convert the libraries or we can do it in one step, but first let’s change directories to make it easier to work with:

cd cli/target

For windows and mac users, if you want to download and then convert you can use the following:

java -jar apache-flex-sdk-converter-1.0.0-SNAPSHOT.jar -flexVersion 4.14.1 -flashVersions 17.0 -airVersion 17.0 -platforms WINDOWS,MAC -fontkit -fdkDir {fdk-dir} download

For linux users, use the next one as Linux is limited to flash version 11.1 and air version 2.6:

java -jar apache-flex-sdk-converter-1.0.0-SNAPSHOT.jar -flexVersion 4.14.1 -flashVersions 11.1 -airVersion 2.6 -platforms LINUX -fontkit -fdkDir {fdk-dir} download

The conversion step is common for all platforms:

java -jar apache-flex-sdk-converter-1.0.0-SNAPSHOT.jar -fdkDir {fdk-dir} -mavenDir {maven-dir} convert

Please don’t forget to replace {fdk-dir} and {maven-dir} with appropriate directories.

For example, the next variant downloads and coverts in one step for Mac (just change the versions for Linux) and published the result to the local maven repository:

java -jar apache-flex-sdk-converter-1.0.0-SNAPSHOT.jar -flexVersion 4.14.1 -flashVersions 14.0 -airVersion 14.0 -platforms WINDOWS,MAC -fontkit -mavenDir ~/.m2/repository/ download convert

If you want to publish to a private repository, please check its parameters or look on its official documentation here.

Now that we have set up all dependencies, it’s time to fill in the pom.xml with missing dependencies and plugins. The following one is an example for a generic project for linux.

<?xml version="1.0" encoding="UTF-8"?>
<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.company</groupId>
	<artifactId>product</artifactId>
	<version>1.0-SNAPSHOT</version>
	<packaging>swf</packaging>

	<name>Company product name</name>

	<properties>
		<flexmojos.version>7.1.0-SNAPSHOT</flexmojos.version>
		<flex.version>4.14.1</flex.version>
		<fontkit.version>1.0</fontkit.version>
		<flashplayer.version>11.1</flashplayer.version>
		<flexunit.version>4.0-rc-1</flexunit.version>
	</properties>

	<build>
		<sourceDirectory>src/main/</sourceDirectory>
		<testSourceDirectory>src/test/</testSourceDirectory>
		<plugins>
			<plugin>
				<groupId>net.flexmojos.oss</groupId>
				<artifactId>flexmojos-maven-plugin</artifactId>
				<version>${flexmojos.version}</version>
				<extensions>true</extensions>
				<configuration>
					<headlessServer>true</headlessServer>
					<verboseStacktraces>true</verboseStacktraces>
					<debug>true</debug>
				</configuration>
				<dependencies>
					<dependency>
						<groupId>org.apache.flex</groupId>
						<artifactId>compiler</artifactId>
						<version>${flex.version}</version>
						<type>pom</type>
					</dependency>
					<dependency>
						<groupId>com.adobe</groupId>
						<artifactId>fontkit</artifactId>
						<version>${fontkit.version}</version>
					</dependency>
				</dependencies>
			</plugin>
		</plugins>
	</build>

	<repositories>
		<repository>
			<id>Flexmojos Repository</id>
			<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
		</repository>
		<repository>
			<id>flex-mojos-repository</id>
			<url>http://repository.sonatype.org/content/groups/flexgroup</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
		<repository>
			<id>Apache Repository</id>
			<url>https://repository.apache.org/content/groups/public/</url>
		</repository>
	</repositories>

	<pluginRepositories>
		<pluginRepository>
			<id>Flexmojos Repository</id>
			<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
		</pluginRepository>
		<pluginRepository>
			<id>Apache Repository</id>
			<url>https://repository.apache.org/content/groups/public/</url>
		</pluginRepository>
		<pluginRepository>
			<id>flex-mojos-plugin-repository</id>
			<url>http://repository.sonatype.org/content/groups/flexgroup</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</pluginRepository>
	</pluginRepositories>

	<dependencies>
		<dependency>
			<groupId>org.apache.flex</groupId>
			<artifactId>framework</artifactId>
			<version>${flex.version}</version>
			<type>pom</type>
		</dependency>
		<dependency>
			<groupId>com.adobe.flash.framework</groupId>
			<artifactId>playerglobal</artifactId>
			<version>${flashplayer.version}</version>
			<type>swc</type>
		</dependency>
		<dependency>
			<groupId>com.adobe.flexunit</groupId>
			<artifactId>flexunit</artifactId>
			<version>${flexunit.version}</version>
			<type>swc</type>
			<scope>test</scope>
		</dependency>
	</dependencies>

</project>

Now as for the actual code for this project, I’ve used a simple Main.as file located in the src/main/ folder and I’ve remove all pre-generated files and folders both from the src/main/ and src/test/ folders.

package
{
	public class Main {
	    public function Main()
	    {
	    }
	}
}

If you’ve managed to set up everything, you can now run

mvn install

and everything should compile nicely, though there are no tests to run but about that in a future post.

If you have any issues or comments please let me know and I will gladly help you.

3 thoughts on “ActionScript Build Automation with Maven and FlexMojos”

  1. Hi Victor,
    Thanks a lot for this post. It helped me set up my first actionscript project through maven.

    One thing that you might want to update and might help others as well going forward:
    Regarding cd flex-utilities/mavenizer – the mavenizer folder is flex-maven-tools/flex-sdk-converter (i believe).

    Also, worth mentioning that the latest flash player release for linux is 11.2 (instead of 11.1).

    Also, It would be great if you will be writing about adding tests as well. I would love to read about that.

    Thanks again!

    1. Hi Aurelian, I was aware of the changes however I’ve yet to update the blog post. I also plan to do one on automation with Gradle.

Leave a Reply

Your email address will not be published. Required fields are marked *