Search code examples
maventimestampmaven-3

How to access maven.build.timestamp for resource filtering


I am using maven 3.0.4 and would like to make the build timestamp accessible to my application. For this, I'm putting a placeholder in a .properties file and let maven filter on build. While this is working fine for ${project.version}, ${maven.build.timestamp} is not substituted on filtering.

The property seems to be available on build - I can use it to modify the artifact name:

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

So why is it not available for resource filtering? And, more importantly, how do I make it accessible?


Solution

  • I have discovered this article, explaining that due to a bug in maven, the build timestamp does not get propagated to the filtering. The workaround is to wrap the timestamp in another property:

    <properties>
       <timestamp>${maven.build.timestamp}</timestamp>
       <maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
    </properties>
    

    Filtering then works as expected for

    buildTimestamp=${timestamp}