Posts Tagged ‘POM’

Maven compilation of Flex project with Mate

Tuesday, April 6th, 2010

One year ago I was trying to use Maven to compile Flex applications. At the time the various flex-mojos (Maven plugins to compile Flex) were still a bit unstable and hard to use. Since then things have evolved and Flex compilation with Maven is now a reality.

In one of our latest projects I decided to create the POM for Flex compilation with Maven using the latest version of the flex-mojos. The reason is that compiling with Maven makes it possible to use Continuous Integration programs like Hudson. Of course compilation with Ant is also a possibility, but if possible I think Maven compilation is much cleaner than Ant, which always feels like hacky code. I run Hudson on our online server that will continuously get the latest version of each of our projects, compile them and send emails to the people breaking the code. This saves a lot time and frustration in the daily work and guarantees that the latest version in our repository is always compiling and the unit tests running. Soon, my goal is to integrate Flex Monkey in the continuos integration setup, so we can easier catch broken code and bugs, since very little of our Flex code is actually unit tested.

Nevertheless I have included an example of a POM for Flex compilation with Maven. I have erased some sensitive names and I have added some comments for clarity.

This particular project uses the Mate framework and integrates another project. Furthermore it uses source code (not included as dependencies). And last but not least, we have created our own repository online, where we can share project dependencies. This repository can be maintained by using Maven to install the dependencies (e.g. mvn install:install-file..) or by installing in the local repository and transferring the files online with FTP.

In this way, I can set up the project dependencies and everyone else involved with the project only needs to compile with Maven and the dependencies will automatically be loaded from the repository.

<?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>

    <!--
    ***********************************************
        Project specification
    ***********************************************
    -->
    <groupId>com.projectname</groupId>
    <artifactId>projectname</artifactId>
    <version>0.1.0-SNAPSHOT</version>
    <packaging>swf</packaging>

    <name>Project Name</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <flex.sdk.version>4.0.0.14159</flex.sdk.version>
        <flex-mojos.version>3.6</flex-mojos.version>
        <mate.version>0.8.9</mate.version>
    </properties>

    <!--
    ***********************************************
        Local configuration
    ***********************************************
    -->
    <build>
        <sourceDirectory>src</sourceDirectory>
        <finalName>ProjectName</finalName>
        <plugins>
            <plugin>
                <groupId>org.sonatype.flexmojos</groupId>
                <artifactId>flexmojos-maven-plugin</artifactId>
                <extensions>true</extensions>

				<configuration>
					<sourceFile>Main.mxml</sourceFile>

                    <!-- set the runtime locale and include the resources frome each project with locales -->
					<runtimeLocales>
					    <locale>en_US</locale>
					</runtimeLocales>
                    <resourceBundlePath>${basedir}/src/locale/{locale}</resourceBundlePath>
                    <resourceBundlePath>/FairgoCRMplugin/src/locale/{locale}</resourceBundlePath>
				</configuration>

                <dependencies>
                    <dependency>
                        <groupId>com.adobe.flex</groupId>
                        <artifactId>compiler</artifactId>
                        <version>${flex.sdk.version}</version>
                        <type>pom</type>
                    </dependency>
                </dependencies>
            </plugin>

            <!-- Plugin to include source paths from other projects when compiling -->
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>build-helper-maven-plugin</artifactId>
				<executions>
					<execution>
						<phase>generate-sources</phase>
						<goals>
							<goal>add-source</goal>
						</goals>
						<configuration>
							<sources>
                                <source>/webresponsivelibrary/trunk/Webresponsive/src</source>
                                <source>/webresponsivelibrary/trunk/XIFF/src</source>
                                <source>/webresponsivelibrary/trunk/MateExtensions/src</source>
                                <source>/FairgoCRMplugin/src</source>
							</sources>
						</configuration>
					</execution>
				</executions>
			</plugin>

        </plugins>

		<pluginManagement>
			<plugins>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-resources-plugin</artifactId>
					<version>2.4</version>
				</plugin>
			</plugins>
		</pluginManagement>
    </build>

    <dependencies>
        <!--
        ***********************************************
            Flex Framework
        ***********************************************
        -->
        <dependency>
            <groupId>com.adobe.flex.framework</groupId>
            <artifactId>flex-framework</artifactId>
            <version>${flex.sdk.version}</version>
            <type>pom</type>
        </dependency>

        <!--
        ***********************************************
            Mate Framework
        ***********************************************
        -->
        <dependency>
            <groupId>com.asfusion</groupId>
            <artifactId>mate</artifactId>
            <version>${mate.version}</version>
            <type>swc</type>
        </dependency>

        <!--
        ***********************************************
            JPEGEncoder
        ***********************************************
        -->
        <dependency>
            <groupId>extra</groupId>
            <artifactId>jpegencoder</artifactId>
            <version>1.0</version>
            <type>swc</type>
        </dependency>
	</dependencies>

    <repositories>
        <!--
        ***********************************************
            Sonatype flex-mojos repository
        ***********************************************
        -->
        <repository>
            <id>flex-mojos-repository</id>
            <url>http://repository.sonatype.org/content/groups/flexgroup</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>

        <!--
        ***********************************************
            Own repository
        ***********************************************
        -->
        <repository>
            <id>Web Responsive repository</id>
            <name>Online Web Responsive Repository</name>
            <url>http://web-responsive/repository</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>flex-mojos-repository</id>
            <url>http://repository.sonatype.org/content/groups/flexgroup</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>

Post to Twitter