6
6

More than 5 years have passed since last update.

Mavenビルドの成果物のバージョンをタイムスタンプにする方法

Last updated at Posted at 2014-11-28

はじめに

"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が生成されます。

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6