Adding the current date with Maven2 filtering

You can use the Maven Buildnumber Plugin for this:

<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>buildnumber-maven-plugin</artifactId>
      <executions>
        <execution>
          <phase>initialize</phase>
          <goals>
            <goal>create</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <doCheck>false</doCheck>
        <doUpdate>false</doUpdate>
        <timestampFormat>{0,date,yyyy-MM-dd HH:mm:ss}</timestampFormat>
      </configuration>
    </plugin>
  </plugins>
</build>

The date is then available in the property ${buildNumber}.


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.


Since Maven 2.1 M1, you can now do ${maven.build.timestamp} provided you also define ${maven.build.timestamp.format}

<properties>
    ...
    <maven.build.timestamp.format>yyyyMMdd-HHmm</maven.build.timestamp.format>
    ...
</properties>