Timestamp-maven-plugin

From Evgeny Goldin

(Redirected from Maven-timestamp-plugin)
Jump to: navigation, search

Contents

Introduction

Historically, there were no easy ways in Maven to set a ${timestamp} property and other alternatives were developed. "timestamp-maven-plugin" is another fix to this problem:


<plugin>
    <groupId>com.github.goldin</groupId>
    <artifactId>timestamp-maven-plugin</artifactId>
    <version>0.2.5</version>
    <executions>
        <execution>
            <id>set-build-timestamp</id>
            <goals>
                <goal>timestamp</goal>
            </goals>
            <phase>validate</phase>
            <configuration>
                <timestamp>
                    <property>timestamp</property>
                    <pattern>MMM dd, yyyy (HH:mm)</pattern>
                    <timezone>GMT+2</timezone>
                    <locale>UK</locale>
                </timestamp>
            </configuration>
        </execution>
    </executions>
</plugin>


Details

Provided By
Mailing List Nabble
Source Code GitHub
Tests GitHub
GroovyDoc <groovydoc>
Issue Tracker YouTrack
Build Server Maven
TeamCity
Maven Coordinates
  • com.github.goldin:timestamp-maven-plugin:0.2.5
Goal
  • timestamp
Default Phase
  • validate
Maven Repository Artifactory


<configuration>

You can define a single <timestamp>:


<configuration>
    <runIf>{{ .. }}</runIf>
    <timestamp>
        <property>build-timestamp</property>
        <pattern>MMM dd, yyyy (HH:mm)</pattern>
    </timestamp>
</configuration>


.. or multiple <timestamps>:


<configuration>
    <runIf>{{ .. }}</runIf>
    <timestamps>
        <timestamp>
            <property>build-timestamp-date</property>
            <pattern>MMM dd, yyyy</pattern>
        </timestamp>
        <timestamp>
            <property>build-timestamp-time</property>
            <pattern>HH:mm</pattern>
        </timestamp>
    </timestamps>
</configuration>


  • <runIf> is optional. It specifies if plugin needs to be run, see "copy-maven-plugin" documentation for more details.
  • Each <timestamp> can have <timezone> and <locale> specified:


<configuration>
    <timestamp>
        <property>build-timestamp</property>
        <pattern>MMM dd, yyyy (HH:mm)</pattern>
        <timezone>EST</timezone>
        <locale>en_US</locale>
    </timestamp>
</configuration>



Groovy

When not specified explicitly new Date() is used for taking a timestamp. Sometimes "now" isn't good enough and for those cases, <time> Groovy snippet can be used to specify another Date, relative to "now" or parsed from another String:


<configuration>
    <!-- "now" + 7 days -->
    <time>{{ new Date().plus( 7 ) }}</time>
    <timestamp>
        <property>future-timestamp</property>
        <pattern>MMM dd, yyyy (HH:mm)</pattern>
    </timestamp>
</configuration>
 
<configuration>
    <!-- "Aug 10, 2009" => "10/08/09" -->
    <time>{{ Date.parse( "MMM dd, yyyy", "Aug 10, 2009" ) }}</time>
    <timestamp>
        <property>timestamp</property>
        <pattern>dd/MM/yy</pattern>
    </timestamp>
</configuration>
 
<properties>
    <format>MMM dd, yyyy</format>
    <time>Aug 10, 2009</time>
</properties>
 
<configuration>
    <!-- "Aug 10, 2009" => "10/08/09" -->
    <time>{{ Date.parse( format, time ) }}</time>
    <timestamp>
        <property>timestamp</property>
        <pattern>dd/MM/yy</pattern>
    </timestamp>
</configuration>


  • Snippet's return value is expected to be an instance of java.util.Date.
  • Maven properties are available as Groovy variables.
Personal tools