Ryan Ryan - 3 months ago 7x
Java Question

How do I add time-stamp information to Maven artifacts?

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


    should be building


    (where the
    is just a
    time-stamp of when the jar is

    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,
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!


Maven versions 2.1.0-M1 or newer have built in special variable maven.build.timestamp.


See Maven documentation for more details.

For older Maven versions a look at maven-timestamp-plugin or buildnumber-maven-plugin.

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


And this configuration for buildnumber-maven-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.



These three sites are also worth checking out.