HOWTO: add a svn build number and timestamp to swf using maven

71 views
Skip to first unread message

Paul Mietz Egli

unread,
Feb 20, 2008, 5:52:14 PM2/20/08
to Israfil Mojo User Discussions
I wanted to add a build number and build date to the settings screen
of my Flex 3 app, but couldn't find a simple description of how to do
this using Maven. Here are the steps, including all of the gotchas.
I'm assuming you already have the maven-flex2-plugin working, and if
you don't, why not?

1. Add the buildnumber-maven-plugin (http://mojo.codehaus.org/
buildnumber-maven-plugin/) to your pom.xml. This plugin queries the
source control repository for the current build number and stores it
in the Maven variable named ${buildNumber}. It also stores the
current date and time in ${timestamp}.

<pluginRepositories>
<pluginRepository>
<releases>
<enabled>false</enabled>
</releases>
<snapshots />
<id>Maven Snapshots</id>
<url>http://snapshots.maven.codehaus.org/maven2/</url>
</pluginRepository>
</pluginRepositories>
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>false</doCheck>
<doUpdate>true</doUpdate>
</configuration>
</plugin>
</plugins>

2. Ensure that you have your source control repository configured in
the pom. Subversion scm config shown here. The trick is to use
<developerConnection>, not <connection> -- otherwise, the buildnumber
plugin will complain.

<scm>
<developerConnection>scm:svn:http://svn.example.com/svn/calculator/
trunk</developerConnection>
<url>http://svn.example.com/svn/calculator/trunk</url>
</scm>

3. Use the <extraParameters> tag to add defines to your mxmlc command
line. Note the quotes around the buildNumber and timestamp values.

<plugin>
<groupId>net.israfil.mojo</groupId>
<artifactId>maven-flex2-plugin</artifactId>
<version>1.3</version>
<extensions>true</extensions>
....
<configuration>
....
<extraParameters>
<parameter>
<name>compiler.define</name>
<values>
<value>EXAMPLE::buildNumber</value>
<value>"${buildNumber}"</value>
</values>
</parameter>
<parameter>
<name>compiler.define</name>
<values>
<value>EXAMPLE::buildTimestamp</value>
<value>"${timestamp}"</value>
</values>
</parameter>
</extraParameters>
</configuration>
</plugin>

4. Use the defined values in your MXML or AS files as described in the
documentation (http://livedocs.adobe.com/labs/flex3/html/
compilers_21.html#246171)

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="init()">
<mx:Script>
<![CDATA[
private function init():void {
var dt:Date = new Date();
dt.setTime(FP::buildTimestamp);
timestampLabel.text = dateFormatter.format(dt);
buildNumberLabel.text = FP::buildNumber;
}
]]>
</mx:Script>
<mx:DateFormatter id="dateFormatter" formatString="D MMM YYYY
JJ:NN"/>
<mx:Label text="version:"/>
<mx:Label id="buildNumberLabel" width="100"/>
<mx:Label text="date:"/>
<mx:Label id="timestampLabel" width="200"/>
</mx:Canvas>

That's it! YMMV on different source control systems, of course.

p.

Paul Mietz Egli

unread,
Feb 20, 2008, 5:54:20 PM2/20/08
to Israfil Mojo User Discussions
Errata #1:

Use "EXAMPLE" instead of "FP" as the namespace in the MXML code; e.g:

<mx:Script>
<![CDATA[
private function init():void {
var dt:Date = new Date();
dt.setTime(EXAMPLE::buildTimestamp);
timestampLabel.text = dateFormatter.format(dt);
buildNumberLabel.text = EXAMPLE::buildNumber;
}
]]>
</mx:Script>
Reply all
Reply to author
Forward
0 new messages