Adding libraries to compilation…

This is a how to post.

When developing with flex, is very common the need for 3rd party libraries to build more elaborated application.  If you wanna charts you must add datavisualization.swc.  If wanna SHA1 algoritm you need as3corelib. So go on…

Using Adobe’s command line compilers (mxmlc and compc) you will use any (or many) parameters from this list:

-compiler.external-library-path
-compiler.include-libraries
-compiler.library-path
-runtime-shared-library-path

But on flex-mojos that options are not available.  If there is no option available, how to add dependencies?

Simple, following maven way =D

Each required library must be add as a dependency.  So, if you need datavisualization you will add a dependency like this:
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>datavisualization</artifactId>
<version>3.0.0.477</version>
<type>swc</type>
</dependency>

One big question: How to discovery dependency groupId and artifactId?
Well who make the library must define it. Since maven is not very popular on flex world it provably will not be defined and not available at any maven repository.

When you face this, you will define your own groupId/artifactId and install on your repository by hand.

Maven Guide to installing 3rd party JARs

Often times you will have 3rd party JARs that you need to put in your local repository for use in your builds. The JARs must be placed in the local repository in the correct place in order for it to be correctly picked up by Maven. To make this easier, and then error prone, we have provide a goal in the install plug-in which should make this relatively painless. To install a JAR in the local repository use the following command:
mvn install:install-file -Dfile= -DgroupId= \
-DartifactId= -Dversion= -Dpackaging=

You can follow the same logic for swc libraries.

And how to define how the dependency should be used? If it should be external, how to get it?
Defining dependency scope:
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>datavisualization</artifactId>
<version>3.0.0.477</version>
<type>swc</type>
<scope>external</scope>
</dependency>

Flex-mojos supports 6 scopes:

    external to -compiler.external-library-path
    internal to -compiler.include-libraries
    merged to -compiler.library-path
    rsl to -runtime-shared-library-path for SWF files
    caching to -runtime-shared-library-path for SWZ files
    test to -compiler.library-path only for test running

If not defined will assumed merged as default.

To read more about flex-mojos scopes click here.

Have a nice weekend every body.

VELO

3 Responses to “Adding libraries to compilation…”

  1. Eduardo Burgos Says:

    Great common sense post for maven flex developers.

  2. Nicolas Martignole Says:

    Question : I tried to add this dependency to my pom.xml but it doesn’t work and the maven url does not contain any SWC file
    (http://flex-mojos.googlecode.com/svn/trunk/repository/com/adobe/flex/sdk/datavisualization/3.0.0.3.0.0.477/)

    com.adobe.flex.sdk
    datavisualization
    swc
    external
    3.0.0.3.0.0.477

    Do you have any clue about how to fix this ?

    Thanks

    nicolas

  3. velo Says:

    Hi Nicolas…

    That is right. datavisualization isn’t open source. Because of that I will not add datavisualization.swc on flex-mojos maven repository.

    If you need, you must install it by hand.

    You can see instructions to that on dashboard wiki:
    http://code.google.com/p/flex-mojos/wiki/DashboardSamplePom

    VELO

Leave a Reply