Adding svn build number and timestamp

As inspired by this post, I wanted to add the svn build number and a timestamp to our application’s about box. This is how to achieve this with flex-mojos:

First, configure your pom to use the buildnumber plugin as such (this requires that you have a command line subversion client installed and on your path):

  <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>
<plugin>
<groupId>info.rvin.mojo</groupId>
<artifactId>flex-compiler-mojo</artifactId>
<configuration>
<defines>
<BUILD::buildNumber>${buildNumber}</BUILD::buildNumber>
<BUILD::timestamp>${timestamp}</BUILD::timestamp>
</defines>
</configuration>
</plugin>
</plugins>
</build>
Then, you can use this value like this in your code:
// application version
public static const VERSION:String = “1.0″;
// stores the svn build number
public static const BUILD_NUMBER:Number = BUILD::buildNumber;  

// stores the timestamp of the last build
public static const BUILD_TIMESTAMP:Date = new Date(BUILD::timestamp);

 

In our About box, we have:


<mx:Label text="Version: {VERSION} Build: {BUILD_NUMBER} Time: {BUILD_TIMESTAMP.toLocaleString()}"
selectable="true" />

You will then need to these variables to your Flex Builder compiler settings (Project Properties, Flex Compiler):
-locale en_US -define=BUILD::buildNumber,0 -define=BUILD::timestamp,0

If someone knows of a better way to integrate the maven values and Flex Builder, post a comment.

3 Responses to “Adding svn build number and timestamp”

  1. You can have the resources plugin filter values into sources when copying them (the resources) from src to target. You can copy a .as3 file with ${buildNumber} in it, and have a value inserted when copied to target.

    The hard thing will be to have flex-mojos compiler plugin grab the sources from target too (the ones copied), but I guess you know how to do this? :)

  2. Instead of putting them in target, I think the right way would be to use the generate-sources phase and put them in a generated-sources directory which would be added to the compile source path

  3. I have posted to groups an issue I’m having, and would like to cross-reference it from here.

    http://groups.google.com/group/flex-mojos/browse_thread/thread/fe9ca36599ed645b

Discussion Area - Leave a Comment