You can use the build-helper-maven-plugin
for this task. It has a timestamp-property
goal that can be used to store a timestamp with a given format into a Maven property:
Sets a property based on the current date and time.
The advantage is that it doesn't force you to define a specific maven.build.timestamp.format
, which would not be convenient if you intend to format the current date in a second way elsewhere. A sample configuration would be:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>timestamp-property</id>
<goals>
<goal>timestamp-property</goal>
</goals>
<phase>validate</phase>
<configuration>
<name>current.year</name>
<pattern>yyyy</pattern>
</configuration>
</execution>
</executions>
</plugin>
This will store the current year in the current.year
Maven property. This is done at the validate
phase, which is the first phase executed, so that all of the rest of the build can use it with ${current.year}
.