views:

741

answers:

4

I am upgrading a large build-system to use Maven2 instead of Ant, and we have two related requirements that I'm stuck on:

  1. We need to generate a time-stamped artifact, so a part of the package phase (or wherever), instead of building

    project-1.0-SNAPSHOT.jar
    

    we should be building

    project-1.0-20090803125803.jar
    

    (where the 20090803125803 is just a YYYYMMDDHHMMSS time-stamp of when the jar is built).

    The only real requirement is that the time-stamp be a part of the generated file's filename.

  2. The same time-stamp has to be included within a version.properties file inside the generated jar.

This information is included in the generated pom.properties when you run, e.g., mvn package but is commented out:

#Generated by Maven
#Mon Aug 03 12:57:17 PDT 2009

Any ideas on where to start would be helpful! Thanks!

+4  A: 

Have a look at maven-timestamp-plugin or maven-build-number-plugin.

If you use maven-buildnumber-plugin, you can use something like this to manipulate resulting artifact name.

<build>
   <finalName>${project.artifactId}-${project.version}-${timestamp}</finalName>
</build>

And this configuration for maven-buildnumber-plugin should create a ${timestamp} property which contains the timestamp value. There doesn't seem to be a way to create the version.properties file directly with this plugin.

    <configuration>
      <format>{0,date,yyyyMMddHHmmss}</format>
      <items>
        <item>timestamp</item>
      </items>

    </configuration>

These three sites are also worth checking out.

Juha Syrjälä
You may be able to create your version.properties file by stubbing it out in /src/main/resources and using filtering. Then use the ${timestamp} property in the filter. The trick would be getting the ${timestamp} property created before the filters are applied.
Mike Cornell
+1  A: 

When a SNAPSHOT project is deployed, by default a timestamp is used unless you override it in the deploy plugin. If you're not getting unique timestamps, it is probably down to a configuration of your Maven repository. As the other answer says though, use the timestamp or buildnumber plugin for releases.

Rich Seller
A: 

Unless you really need all the stuff provided by maven, but just want the dependency management, then have a look at the Ivy extension for Ant which is compatible with maven without having to eat the whole cake.

Thorbjørn Ravn Andersen
+1  A: 

If you use a version of Maven >= 2.1.0-M1, then you can use the ${maven.build.timestamp} property.

For more info, see: http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Available%5FVariables

Horia Chiorean