Maven + system Date

datemaven-2

I'm working in a project that already have a build process running with maven.

Today the build generates a zip file in a given directory, but I need to add the DATE pattern in the file, something like 200917_projectName.zip

Someone have any clue?

Thanks in advance

Best Solution

Using the build-number-maven-plugin allows you to generate a property that can then be used in the finalName property.

The following configuration sets a timestamp property with the format you required, then modifies the finalName to use that property and result in an artifact with that name being output to the target directory.

Note that this name is ignored when installing/deploying the artifact, otherwise Maven would not be able to reliably locate artifacts.

<build>
  <finalName>${buildNumber}_${project.artifactId}</finalName>
  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>buildnumber-maven-plugin</artifactId>
      <version>1.0-beta-3</version>
      <executions>
        <execution>
          <phase>validate</phase>
          <goals>
            <goal>create</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <format>{0,date,yyyyMM}</format>
        <items>
          <item>timestamp</item>
        </items>
      </configuration>
    </plugin>
  ...
  </plugins>
...
</build>