はじめに
"hoge" という名前のJARパッケージを開発している際に、
成果物の名前を「hoge-0.0.1-SNAPSHOT」等ではなくタイムスタンプを入れたい場合があります。
下記のサンプルのPOMファイルのように "gmaven-plugin" を利用すると実現する事が可能です。
サンプルのPOMファイル
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.hirokapi</groupId>
<artifactId>hirokapi</artifactId>
<packaging>jar</packaging>
<name>The Hirokapi Project</name>
<version>0.0.1</version>
: : :
<build>
: : :
<!-- <finalName>${artifactId}-${version}</finalName> -->
<finalName>${artifactId}-${timestamp}</finalName>
: : :
<plugins>
: : :
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>set-custom-property</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
def timestamp = new Date().format('yyyyMMdd.HHmmss')
project.properties.setProperty('timestamp', timestamp)
</source>
</configuration>
</execution>
</executions>
</plugin>
: : :
</plugins>
</build>
: : :
</project>
成果物
上記のPOMでビルドすると、「hirokapi-20141129.200650.jar」のようなJARが生成されます。