Git Timestamp Maven Plugin

A plugin that computes a consistent timestamp based on your git sources.

License

License

Categories

Categories

Maven Build Tools Git Development Tools Version Controls
GroupId

GroupId

com.github.stephenc.continuous
ArtifactId

ArtifactId

git-timestamp-maven-plugin
Last Version

Last Version

1.47
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

Git Timestamp Maven Plugin
A plugin that computes a consistent timestamp based on your git sources.
Source Code Management

Source Code Management

http://github.com/stephenc/git-timestamp-maven-plugin/tree/master/

Download git-timestamp-maven-plugin

How to add to project

<plugin>
    <groupId>com.github.stephenc.continuous</groupId>
    <artifactId>git-timestamp-maven-plugin</artifactId>
    <version>1.47</version>
</plugin>

Dependencies

compile (17)

Group / Artifact Type Version
org.apache.maven : maven-model jar 3.0.5
org.apache.maven : maven-core jar 3.0.5
org.apache.maven : maven-plugin-api jar 3.0.5
org.codehaus.plexus : plexus-utils jar 2.0.5
org.codehaus.plexus : plexus-container-default jar 1.0-alpha-9
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.0
org.apache.maven.scm : maven-scm-api jar 1.9.5
org.apache.maven.scm : maven-scm-manager-plexus jar 1.9.5
org.apache.maven.scm : maven-scm-provider-bazaar jar 1.9.5
org.apache.maven.scm : maven-scm-provider-svnexe jar 1.9.5
org.apache.maven.scm : maven-scm-provider-gitexe jar 1.9.5
org.apache.maven.scm : maven-scm-provider-svn-commons jar 1.9.5
org.apache.maven.scm : maven-scm-provider-cvsexe jar 1.9.5
org.apache.maven.scm : maven-scm-provider-starteam jar 1.9.5
org.apache.maven.scm : maven-scm-provider-clearcase jar 1.9.5
org.apache.maven.scm : maven-scm-provider-perforce jar 1.9.5
org.apache.maven.scm : maven-scm-provider-hg jar 1.9.5

Project Modules

There are no modules declared in this project.

Git Timestamp Maven Plugin

Experimental plugin to assist with applying continuous delivery to Maven based projects.

If you are following the type of release pattern described in this blog post you may need a way to assign "version numbers" for the developer local builds.

This plugin will infer a timestamp from the state of the git repository. The timestamp will have two parts:

  • The time of the most recently modified tracked file in the workspace.

  • The number of commits on the current branch.

The timestamp can then be injected into a system property (for use in filtering resources) and/or can be writted to a file.

Additionally, the timestamp can be substituted into the project version. By default release versions will be left alone, but -SNAPSHOT versions will have the -SNAPSHOT replaced by the timestamp. The modified version can then be injected into a system property (for use in filtering resources) and/or can be writted to a file.

For example, the configuration:

<project ...>
  ...
  <version>1.x-SNAPSHOT</version>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        ...
        <artifactId>maven-release-plugin</artifactId>
        ...
        <configuration>
          <localCheckout>true</localCheckout>
          <pushChanges>false</pushChanges>
          <releaseVersion>1.${env.BUILD_NUMBER}</releaseVersion>
          <developmentVersion>1.x-SNAPSHOT</developmentVersion>
        </configuration>
      </plugin>
      ...
      <plugin>
        <groupId>com.github.stephenc.continuous</groupId>
        <artifactId>git-timestamp-maven-plugin</artifactId>
        ...
        <executions>
          <execution>
            <goals>
              <goal>timestamp</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <versionFile>${project.build.outputDirectory}/version.txt</versionFile>
        </configuration>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

Will populate the version.txt file with a version like 1.x-20180220.191333-54 for developer builds.

When the release is done on the CI server (which defines the environment variable BUILD_NUMBER then the version.txt file will be populated with a version like 1.67

This way, developer build will have a version number in the version.txt that is reflective of their local changes and will increase as they make newer modifications.

Additionally, release versions will always be seen as newer than developer builds (because 1.x is less than 1.1 using Maven’s version number comparison rules).

Release assistance

This plugin can also assist the Apache Maven Release plugin. For example:

For example, the configuration:

<project ...>
  ...
  <version>1.x-SNAPSHOT</version>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        ...
        <artifactId>maven-release-plugin</artifactId>
        ...
        <configuration>
          <localCheckout>true</localCheckout>
          <pushChanges>false</pushChanges>
        </configuration>
      </plugin>
      ...
      <plugin>
        <groupId>com.github.stephenc.continuous</groupId>
        <artifactId>git-timestamp-maven-plugin</artifactId>
        ...
        <configuration>
          <snapshotText>x-SNAPSHOT</snapshotText>
        </configuration>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

Will enable automatic version detection based on the current remote tags and the number of commits when Maven is invoked like so:

mvn git-timestamp:setup-release release:prepare release:perform

Versions

Version
1.47
1.43
1.42
1.41
1.40
1.35
1.32
1.26
1.23
1.20
1.16
1.13
1.3
1.2
1.1
1.0