Adding the current date with Maven2 filtering

Romain Linsolas picture Romain Linsolas · Apr 29, 2009 · Viewed 55.9k times · Source

I have a Maven2 project, and I need to add, in a properties file, the current version and the current date.

For the current version, I've used ${project.version}, which works correctly.

My question is how can I set the current date (i.e. the date when the build is done by Maven2) in my properties file:

client.version=Version ${project.version}
client.build=???

(in addition, if I can specify the format for the date, it will be really great)

Answer

jj. picture jj. · Jan 16, 2010

Feature does not work with maven 2.2.1 resource filtering.

See: https://issues.apache.org/jira/browse/MRESOURCES-99

But you could create a custom property in the parent pom:

<properties>
    <maven.build.timestamp.format>yyMMdd_HHmm</maven.build.timestamp.format>
    <buildNumber>${maven.build.timestamp}</buildNumber>
</properties>

Where buildNumber is the new property that can be filtered into the resources.