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

If you need the time in a timezone other than UTC (the default when you use ${maven.build.timestamp}) you could use the build-helper-maven-plugin. See more in Brief examples on how to use the Build Helper Maven Plugin's goals.

Anyway, this is how I've got the timestamp in GMT-5 and put it in the final name of my artifact:

  <build>
      <plugins>
          <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>build-helper-maven-plugin</artifactId>
              <version>1.9.1</version>
              <executions>
                  <execution>
                      <id>timestamp-property</id>
                      <goals>
                          <goal>timestamp-property</goal>
                      </goals>
                      <configuration>
                          <name>current.time</name>
                          <pattern>yyyyMMdd-HHmmss</pattern>
                          <timeZone>GMT-5</timeZone>
                      </configuration>
                  </execution>
              </executions>
          </plugin>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-jar-plugin</artifactId>
              <version>2.4</version>
              <configuration>
                  <finalName>${project.name}-${current.time}</finalName>
              </configuration>
          </plugin>
      </plugins>
  </build>

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

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

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.

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

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.

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

</configuration>

These three sites are also worth checking out.


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_Variables


This post (especially the below part) is also very useful and practical for this issue.

Stamping Version Number and Build Time in a Properties File with Maven

The pom will look like this

...
<properties>
        
        ....
        
        <!-- Timestamp of build  -->
        <timestamp>${maven.build.timestamp}</timestamp>
        <maven.build.timestamp.format>yyyy_MM_dd_HH_mm</maven.build.timestamp.format>
        
</properties>

...

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

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                ....
            </plugin>
        </plugins>
</build>
....

and the package name is MyProject-1.0.0-2015_03_02_13_46.war