Thomas Marti's answer is a step in the right direction, but there's a simpler approach that does not require a dummy <scm>
declaration in the POM. Use the buildnumber-maven-plugin
, but use the create-timestamp
goal. The documentation isn't clear; here's what it looks like to get a date in YYYY-MM-DD
format and put it in the build.date
property:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create-timestamp</goal>
</goals>
</execution>
</executions>
<configuration>
<timestampFormat>yyyy-MM-dd</timestampFormat>
<timestampPropertyName>build.date</timestampPropertyName>
</configuration>
</plugin>
Out of the box this won't work in Eclipse with m2e, so you'll have to add the following inside the POM <build>
section:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<versionRange>[1.2,)</versionRange>
<goals>
<goal>create-timestamp</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnConfiguration>true</runOnConfiguration>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
This tells m2e that you want it to go ahead and run the plugin when building within Eclipse.
Now when you build inside or outside of Eclipse, the timestamp is correctly generated and works with resource filtering!
It's a shame that functionality so simple has to be so hard...