Search code examples
mavenresourcesfiltersnapshotbuildnumber-maven-plugin

Add a unique snapshot version upon copying resources with filtering


When copying resources with filtering in Maven, I want to add the unique snapshot version to a resource file.

I have enabled filtering:

...
<name>My Application</name>
<version>0.1-SNAPSHOT</version>
...
<build>
  <resources>
    <resource>
      <directory>src/main/resources</directory>
      <filtering>true</filtering>
      ...
    </resource>
  </resources>
  ...
</build>

This is my resource file:

application.name=${name}
application.Version=${version}

After running mvn resources:resources, this is the result:

application.name=My Application
application.Version=0.1-SNAPSHOT

But what I actually want is this:

application.name=My Application
application.Version=0.1-20120310.143733-1

Solution

  • Since version 2.1.0-M1, Maven supports special syntax to get build timestamp in pom.xml, check out the doc here:

    <project>
      ...
      <properties>
        <maven.build.timestamp.format>yyyyMMdd.HHmmss</maven.build.timestamp.format>
      </properties>
      ...
    </project>
    

    Alternatively, you can use buildnumber-maven-plugin.