In order to build Flex applications using Maven you need to prepare the SDK you want to use by converting it into a form Maven can use.

We created the Mavenizer tool, which is part of the flex-utils package. We will probably use this tool in the near future to create Mavenized releases of Flex, but till that is the case you have to manually check out the Mavenizer and run it to create these Mavenized SDKs locally.

You need to perform the following steps:

  1. Do a normal installation of the Flex SDK using the Installer tool (Be sure to check all the checkboxes in order to create a feature complete mavenzied version)
  2. Checkout and build the Mavenizer
  3. Run the Mavenizer
  4. (optional) use a deployer to upload the artifacts to a remote Maven repository
  5. Build an application using Flexmojos

Install Flex SDK

  1. Download and Install the Flex Installer (http://flex.apache.org/installer.html)
  2. Install a Flex SDK locally using the Installer (Installation help)

Checkout and build the Mavenizer

I will describe this on the base of a commandline build as this should work everywhere.

Prerequisites:

  1. Java (http://www.oracle.com/technetwork/java/javase/downloads/index.html) (Eventually it would be best to have a 1.7 SDK installed)
  2. Maven (http://maven.apache.org/download.cgi)
  3. Git (http://git-scm.com/downloads)
    1. If you like a GUI client you can install TortoiseGIT (https://code.google.com/p/tortoisegit/)
  4. Make sure the git and maven bin direcotries are part of your system path (typing "mvn" produces commandline-output as well as "git")

Checking out the flex-utils reoisitory

  1. Clone the repository:

    git clone https://git-wip-us.apache.org/repos/asf/flex-utilities.git utilities
  2. Currently the updated Mavenizer is located in the "master" branch, so we have to switch to that first:  

    git checkout develop

    After this the utilities/mavenizer directory should contain 5 sub-directories. This way you know you are on the right branch.

  3. Build the Mavenizer using Maven: 

    cd utilities/mavenizer 
    mvn clean install

    You will see a lot of log output and hopefully at the end you should be able to read something like this: 

    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 8.620s
    [INFO] Finished at: Sat Jul 12 12:41:42 CEST 2014
    [INFO] Final Memory: 40M/230M
    [INFO] ------------------------------------------------------------------------

    Now you have successfully built the mavenizer. The utilities/mavenizer/core/target directory should now contain 2 jar files "core-1.0.0-SNAPSHOT.jar" and "flex-sdk-converter-1.0.0-SNAPSHOT.jar".

Run the Mavenizer

Assuming you have downloaded and installed the Flex SDK to the directory c:\Temp\Apache-Flex-SDKs\flex-4.12.1 and you want the Mavenizer to produce the output in c:\Temp\mavenized

  1. Create the output directory 

    mkdir c:\Temp\mavenized
  2. Change to the directory where the mavenizer has been created. 

    cd utilities/mavenizer/core/target
  3. Execute the Mavenizer:

    java -jar [path-to-the-sdk-converter-jar]/flex-sdk-converter-1.0.0-SNAPSHOT.jar "c:\Temp\Apache-Flex-SDKs\flex_sdk_4.12.1-apache" "c:\Temp\mavenized"

    After the execution is finished you should have two directories in the "c:\Temp\mavenized" directory "com" and "org". 

Deploy the mavenized SDK

You now have two choices to make the mavenized FDKs available to maven. You can either deploy the artifacts locally and you will be able to use them on your machine, but only your machine. Or you can upload them to a remote Maven repository and make them available to anyone that has access to that reposiotry.

Deploying Apache Flex to a remote repository

In no case should you upload the artifacts to a publically available Repository. Even if you might think that you are doing someting good ... trust me, you are not only pulically making Adobe artifacts available which might result in a lawsuite from Adobe, you are also just making sure we will run into serious trouble in the future. As soon as we are convinced our mavenized artifacts have the right structure, we will release Apache Flex artifacts. Till we are finished with this, the structure might still change slightly. if however there are artifacts out there these will definitely cause problems and conflicts. So: PLEASE DON'T UPLOAD THE FLEX ARTIFACTS TO A PUBLICALLY AVAILABLE MAVEN REPO!

That being said ... let's continue (smile)

As the new Mavenier ist now split up into separate modules. We have split up the code for the deployers into two modules:

  • deployers\maven: Being the classic deployer utilizing Maven for deploying each artifact separately.
  • deployers\aether: Directly accessing the Maven libs for deploying without actually executing maven. This version is faster, but might not work in all cases.

I would recommend to try the aether deployer first as it is easier to use and to fall back to the maven one if you have any problems.

  1. Go to the target directory of the deployer you want to use: 

    cd utilities\mavenizer\deployers\aether\target

    This directory should contain two jar files.

  2. Execute the deployer: 

    java -jar aether-deployer-1.0.0-SNAPSHOT-full.jar "c:\Temp\mavenized" "{url of your remote repository}" "{username}" "{password}"

    Username and password are optional but I pray that you don't have an unsecured remote Maven repository unless you know exactly what you are doing (wink)

  3. You should now see a lot of log output in which the deployer confirms to deploy artifacts to your remote repository.
  4. After the deployment is finished, you can check your repo, if it contains the artifacts by visiting its (The URL you entered as second argument to the deployer).
  5. You're finished ... have fun (smile)

Deploying Apache Flex locally 

So this is actually insanely easy (smile)

First of all you have to check where your Maven local repository is located. I usually do this by:

  • checking if your users home directory has a ".m2" directory (it should)
  • Inside this directory can contain a "settings.xml" file. 
    • If it doesn't the .m2 directory will contain a "repository" directory ... this is your Maven local repository.
    • If it contains a settings.xml open that in a text editor and see if it contains a "localRepository" tag: 
      • if it does, this is your local repository location
      • if it doesn't your local repository location is probably ".m2/repository"

Deploying your Maven artifacts is as simple as:

  1. Copy the entire content of "c:\Temp\mavenized" to your local repository location (Be sure that the "c:\Temp\mavenized\org" directory is now located at ".m2\repository\org" if your local repository was located at ".m2\repository")
  2. You're finished ... have fun (smile)

 

Build an application using Flexmojos

In earlier versions of Flexmojos you needed only to reference the Flex SDK in the version you wanted. As Flex, AIR and Flash artifacts are no longer linked directly you need to at least reference the Flex SDK as well as the runtime libs you want to use (playerglobal or airglobal). As writing down a complete tutorial on this would exceed the scope of this document by far, I'll simply post two sample pom files, one for an swc and one for an swf (actually they are allmost the same) but they should be enough for you to get the main idea.

Currently the version of Flexmojos able to work with the updated Mavenizer structure is the 7.1.0 version.

SWC Artifact

<?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>my.cool.groupId</groupId>
  <artifactId>swc-artifact</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>swc</packaging>

  <build>
    <sourceDirectory>src/main/flex</sourceDirectory>
    <testSourceDirectory>src/test/flex</testSourceDirectory>

    <plugins>
      <plugin>
        <groupId>net.flexmojos.oss</groupId>
        <artifactId>flexmojos-maven-plugin</artifactId>
        <version>7.1.0</version>
        <extensions>true</extensions>
        <dependencies>
          <!-- Without this FM will use the compiler configured in its master pom, which will result in version conflicts -->
          <dependency>
            <groupId>org.apache.flex</groupId>
            <artifactId>compiler</artifactId>
            <version>4.15.0</version>
            <type>pom</type>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <!-- Flex SDK dependencies -->
    <dependency>
      <groupId>org.apache.flex</groupId>
      <artifactId>framework</artifactId>
      <version>4.15.0</version>
      <type>pom</type>
    </dependency>
    <!-- Flashplayer runtime dependencies -->
    <dependency>
      <groupId>com.adobe.flash.framework</groupId>
      <artifactId>playerglobal</artifactId>
      <version>20.0</version>
      <type>swc</type>
    </dependency>
  </dependencies>

</project>

It is important to note that the two versions of the compiler and the framework have to match each other or you will have trouble. In the above configuration you are using Flexmojos 7.1.0 to compile a Flex 4.15.0 application that is able to run in a FlashPlayer 20.0 and above.

SWF Artifact

 

<?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>my.cool.groupId</groupId>
  <artifactId>swf-artifact</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>swf</packaging>

  <build>
    <sourceDirectory>src/main/flex</sourceDirectory>
    <testSourceDirectory>src/test/flex</testSourceDirectory>

    <plugins>
      <plugin>
        <groupId>net.flexmojos.oss</groupId>
        <artifactId>flexmojos-maven-plugin</artifactId>
        <version>7.1.0</version>
        <extensions>true</extensions>
        <configuration>
          <sourceFile>ApplicationMain.mxml</sourceFile>
        </configuration>
        <dependencies>
          <!-- Without this FM will use the compiler configured in its master pom, which will result in version conflicts -->
          <dependency>
            <groupId>org.apache.flex</groupId>
            <artifactId>compiler</artifactId>
            <version>4.15.0</version>
            <type>pom</type>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <!-- Flex SDK dependencies -->
    <dependency>
      <groupId>org.apache.flex</groupId>
      <artifactId>framework</artifactId>
      <version>4.15.0</version>
      <type>pom</type>
    </dependency>
    <!-- Flashplayer runtime dependencies -->
    <dependency>
      <groupId>com.adobe.flash.framework</groupId>
      <artifactId>playerglobal</artifactId>
      <version>20.0</version>
      <type>swc</type>
    </dependency>
  </dependencies>

</project>

In contrast to the SWC Artifact I suggest to add the "sourceFile" attribute to tell the compiler what the main class is. If you don't it will take the first it finds. If there are more than one you could be getting into trouble.

  • No labels