Upgrading flex-mojos 2.0.0 to flexmojos-maven-plugin 3.x
Thursday, March 26. 2009
In case you want to build Flex applications using Maven 2 the Flex Mojo plugin is surely the best Maven 2 plugin to accomplish a fully featured build setup. Unfortunately it lacks documentation. So the best resource for settings up own Maven builds is to look at the examples that the developer Marvin Froeder uses to test the plugin.
Marvin Froeder has also a blog where he used to announce changes. However yesterday I realized that I was still building against the Flex 3.0.0 SDK and was looking for information on how to update the build against the latest 3.3.0 SDK. Fortunately Marvin is very, very fast and responsive in the Google Groups discussion group so I took a look into and searched for information and found a thread, where Flex-Mojo 3.0.0 was mentioned. So I tried to upgrade and get the latest Flex Mojo Maven plugin and it was not as easy as running mvn -up.
So here are the upgrade instructions from flex-mojo 2.0.0 to flexmojos-maven-plugin 3.x:
Note that I am not relying on the generic parent POM flexmojos-flex-super-pom for my builds as the builds are part of a bigger overall build and thus needs to inherit from different parents. In case you are using the super POM, you can skip the changes in the dependency management section.
New Repository
Finding the new repository was actually the hardest part. I still do not understand, why this is not better documented, especially since you cannot look in the examples to figure that out - you have to know it. Even googling did not help so I had to ask Marvin and he replied 6 minutes later. The repository URL has changed from http://svn.sonatype.org/flexmojos/repository to http://repository.sonatype.org/content/groups/public.
So first change the repository entries in your pom files. Once for the dependencies
<repositories>
<!-- ... -->
<repository>
<id>flex-mojos-repository</id>
<url>http://repository.sonatype.org/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<!-- ... -->
</repositories>
and a second time for the plugins:
<pluginRepositories> <!-- ... --> <pluginRepository> <id>flex-mojos-repository</id> <url>http://repository.sonatype.org/content/groups/public</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> <!-- ... --> </pluginRepositories>
New Plugin Artifact
The artifact group ID and artifact ID of plugin itself have also changed. Old artifact ID was info.flex-mojos:flex-compiler-mojo.
<build>
<finalName>${project.artifactId}</finalName>
<sourceDirectory>src/main/flex</sourceDirectory>
<testSourceDirectory>src/test/flex</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.1-SNAPSHOT</version>
<extensions>true</extensions>
<configuration>
<includeSources>
<param>${project.build.sourceDirectory}</param>
</includeSources>
</configuration>
</plugin>
</plugins>
</build>
Note that I am also using a more maven style layout for my sources. All my sources are located in src/main/flex.
Also I am using the 3.1-SNAPSHOT version already. 3.1-SNAPSHOT compiles against Flex SDK 3.3, while the released 3.0.0 plugin compiles against Flex SDK 3.2. I haven't found any problems with 3.1-SNAPSHOT so far, but for release code you should consider the 3.0.0 plugin of course.
Dependency Management
Since I am not relying on the generic parent POM provided by Marvin I have to manage the versions of the Flex SDK dependencies on my own in a common parent POM, which is inherited by all child POMs that are building the actual SWF or SWC files.
The groupID of all artifacts have been changed from com.adobe.flex.sdk to com.adobe.flex.framework. Then there are new artifacts for the resource bundles of the rpc and framework artifacts with a new type of rb.swc.
Here is the old version of the dependency management section.
<dependencyManagement>
<dependencies>
<!-- ... -->
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>playerglobal</artifactId>
<version>3.0.0.3.0.0.477</version>
<type>swc</type>
<scope>external</scope>
</dependency>
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>flex</artifactId>
<version>3.0.0.3.0.0.477</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>framework</artifactId>
<version>3.0.0.3.0.0.477</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>framework</artifactId>
<version>3.0.0.3.0.0.477</version>
<type>swc</type>
<classifier>en_US</classifier>
</dependency>
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>rpc</artifactId>
<version>3.0.0.3.0.0.477</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>rpc</artifactId>
<version>3.0.0.3.0.0.477</version>
<type>swc</type>
<classifier>en_US</classifier>
</dependency>
<dependency>
<groupId>com.adobe.flex.sdk</groupId>
<artifactId>utilities</artifactId>
<version>3.0.0.3.0.0.477</version>
<type>swc</type>
</dependency>
<!-- ... -->
</dependencies>
</dependencyManagement>
And finally the new version, where the group IDs have been replaced by the new IDs and the old resource bundles have been replace with two new artifacts each:
<dependencyManagement>
<dependencies>
<!-- ... -->
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>playerglobal</artifactId>
<version>9-3.3.0.4852</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>flex</artifactId>
<version>3.3.0.4852</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>framework</artifactId>
<version>3.3.0.4852</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>framework</artifactId>
<version>3.3.0.4852</version>
<type>rb.swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>framework</artifactId>
<version>3.3.0.4852</version>
<type>rb.swc</type>
<classifier>en_US</classifier>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>rpc</artifactId>
<version>3.3.0.4852</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>rpc</artifactId>
<version>3.3.0.4852</version>
<type>rb.swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>rpc</artifactId>
<version>3.3.0.4852</version>
<type>rb.swc</type>
<classifier>en_US</classifier>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>utilities</artifactId>
<version>3.3.0.4852</version>
<type>swc</type>
</dependency>
<!-- ... -->
</dependencies>
</dependencyManagement>
This dependency management section is for the current 3.1 snapshot of the Flex Mojos plugin. For the released 3.0.0 version you have to replace the version 3.3.0.4852 with 3.2.0.3958. Also note the version of the playerglobal artifact. When you develop against a Flash player 9.x prefix it with "9-", prefix it with "10-" when developing for Flash player 10.x. In case you are using the 3.0.0 plugin specify a classifier containing 9 or 10 and remove the prefix to get clean transitive dependencies.
Dependencies
Finally in the child POMs you have to change the group IDs of all the dependencies contained in the <dependency> section from com.adobe.flex.sdk to com.adobe.flex.framework and introduce the new resource bundle artifacts for rpc and framework wherever you reference these artifacts as seen in the new dependency management section above in lines 24 to 36 and 43 to 55 (don't forget to remove the version tags in your child POMs).
That's it. When you haven't forgotten to change any reference to a dependency the next build should be able to download all required artifacts and you Flex application will be build against the latest SDK.
Some Tips
After I wrote this article I posted it on the flex-mojos google group and received some tips on how to manage the dependencies more nicely.
In case you don't care having some more dependencies but want a much shorter and cleaner POM file Marvins Tip might be the one to go. Simply replace all the individual flex dependencies by just one entry:
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>flex-framework</artifactId>
<type>pom</type>
<version>3.3.0.4852</version>
</dependency>
Repeat this section omitting the version in your child POMs. In addition to the section listed above this adds the following dependencies:
- applicationupdater-3.3.0.4852.swc
- applicationupdater_ui-3.3.0.4852.swc
- framework-3.3.0.4852-configs.zip
So this might not be your desired approach in case you want to manage dependencies very tightly. In some cases you can even shorten the full list from above e.g. when you don't require the rpc package. In other cases you cannot do that at all, e.g. when you want to load framework libraries as cached RSLs.
A more general tip was provided by Davis Ford, who suggested to define a maven property for the version, so that you do not have to repeat the same version for each artifact. Add a section like the following to your pom:
<properties> <flex-version>3.3.0.4852</flex-version> </properties>
After that you can simply use <version>${flex-version}</version> for all your artifacts and can switch the version just by changing it at one location.
Trackbacks
Trackback specific URI for this entry
Comments
eg.
<groupId>info.flex-mojos</groupId> <artifactId>flex-compiler-mojo</artifactId>
becomes simply
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
and all artifactId have been consolidated really into one
eg.
<groupId>info.flex-mojos</groupId>
<artifactId>html-wrapper-mojo</artifactId>
using the wrapper goal
is now
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
and the wrapper goal remains.
This is pretty much the same pattern everywhere I looked (there could be exceptions).
All specific mojos I found could be renamed to the generic
flexmojos-maven-plugin
artifactId and it looks like the goals now control everything instead.
One other thing worth mentioning is that if you are using unit testing support dependency
<dependency>
<groupId>info.flex-mojos</groupId>
<artifactId>testing-support</artifactId>
<version>${flex-mojos.version}</version>
<type>swc</type>
<scope>test</scope>
</dependency>
this is now
<dependency>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-unittest-support</artifactId>
<version>${flex-mojos.version}</version>
<type>swc</type>
<scope>test</scope>
</dependency>
thanks for your great post. You should probably contribute this to the new wiki the flex-mojos guys are setting up!
thank you very much for these extended informations. Regarding the obsolete testing-support I already noticed that. In fact in caused even Maven problems.
I already wrote another entry regarding this: http://www.yeap.de/blog2.0/archives/188-Unit-Testing-With-Flex-Mojos.html.
But I didn't used the other artifacts so far so I haven't noticed. That will definitely be helpful for other readers.
Best regards,
Carsten
thanks for that blog. I think there is a lot of outdated posts out there :/
I found two little issues:
1. Remove the <dependenyManagement> tags.
2. Use following dependency and kick the old one:
--
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>playerglobal</artifactId>
<version>9-3.3.0.4852</version>
<type>swc</type>
<!--<classifier>9</classifier>-->
</dependency>
--
Now it works properly (for me
Thanks again and greets from Stg!
I guess there is a misunderstanding... The <dependencyManagement> section must go into a common parent POM, while the <dependencies> section will be part of the child POMs that are actually building the SWFs/SWCs.
When you introduce a <dependencyManagement> section in a parent POM you won't have to specify the individual versions in each single child POM.
Hope that helps!
etcetc...
urls[80] = file:/C:/Documents and Settings/1320667/.m2/repository/com/intellij/a
nnotations/6.0.3/annotations-6.0.3.jar
urls[81] = file:/C:/Documents and Settings/1320667/.m2/repository/com/adobe/flex
/compiler/asdoc/3.2.0.3958/asdoc-3.2.0.3958-template.zip
[FATAL ERROR] Container realm = plexus.core
urls[0] = file:/C:/Documents and Settings/1320667/apps/maven-2.0.9/bin/../lib/ma
ven-2.0.9-uber.jar
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] org/jdom/input/SAXBuilder
org.jdom.input.SAXBuilder
[INFO] ------------------------------------------------------------------------
[INFO] Trace
java.lang.NoClassDefFoundError: org/jdom/input/SAXBuilder
at org.sonatype.flexmojos.utilities.MavenUtils.getFDKNamespaces(MavenUti
ls.java:480)
at org.sonatype.flexmojos.utilities.MavenUtils.getFdkNamespaces(MavenUti
ls.java:534)
at org.sonatype.flexmojos.compiler.AbstractFlexCompilerMojo.configure(Ab
stractFlexCompilerMojo.java:1239)
at org.sonatype.flexmojos.compiler.AbstractFlexCompilerMojo.setUp(Abstra
ctFlexCompilerMojo.java:1015)
etcetc...
hm... I am not sure in which stage this happens as there is quite some info missing. Plexus.core sounds like you are preparing reports using mvn site. Is that correct?
In any case it seems like you are missing a jdom dependency. It should be present as transitive dependency. However in my projects I cannot find it. Try running mvn dependency:tree and mvn dependecy:resolve-plugins to see, whether it is required and where it is required.
Best regards,
Carsten
In my case, because I am using maven 2.2.0 release, which apparently does not include jdom.jar in its maven-2.2.0-uber.jar any more (located in $MAVEN_HOME/lib dir). Previous maven release had this jdom.jar included.
Anyway, flex sdk mojo assumes jdom is available from maven, in its absence, hence the classnotfound exception.
My solution, I downloaded jdom-1.1.jar and put it in $MAVEN_HOME/lib dir. Problem solved.
However, I'd like to know how to wrap swf into html file. It seems that html-wrapper-mojo is now obsolete (it can still be used however) and flexmojos-maven-plugin contains everything for now on. I mentioned next line shown during flex compilation:
-verify-digests=true -load-config=
Does it mean I should include configuration code into external xml file? And if yes, how to specify a link to that file in plugin config?
Thanks in advance,
Jaroslav Danilov
I never used the html-wrapper mojo. In general I use the wrapper that is provided by the IDE. IntelliJ IDEA offers a big variety of possible wrappers it ca n generate for you.
You don't need to create a external compiler configuration file. In fact flex-mojos will ignore it, but it generates one based on the Maven configuration. That generated configuration is the one that is used during configuration.
When I tried to update another project to flexmojos-maven-plugin 3.x I realized that I missed a step, when I wrote the upgrade instructions from flex-mojos 2.0.0 to the newer plugin. While the first project was at its very beginning with no Unit tests exi
Tracked: Mar 30, 16:36