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:
I will describe this on the base of a commandline build as this should work everywhere.
Prerequisites:
Checking out the flex-utils reoisitory
Clone the repository:
git clone https://git-wip-us.apache.org/repos/asf/flex-utilities.git utilities |
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.
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".
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
Create the output directory
mkdir c:\Temp\mavenized |
Change to the directory where the mavenizer has been created.
cd utilities/mavenizer/core/target |
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".
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.
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
As the new Mavenier ist now split up into separate modules. We have split up the code for the deployers into two modules:
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.
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.
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
So this is actually insanely easy
First of all you have to check where your Maven local repository is located. I usually do this by:
Deploying your Maven artifacts is as simple as:
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.
<?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.
<?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.