Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/davidmoten/git-properties-maven-plugin

Maven plugin to write a git.properties file to an output directory and to set maven properties for use in pom.xml
https://github.com/davidmoten/git-properties-maven-plugin

Last synced: about 1 month ago
JSON representation

Maven plugin to write a git.properties file to an output directory and to set maven properties for use in pom.xml

Awesome Lists containing this project

README

        

# git-properties-maven-plugin


[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.davidmoten/git-properties-maven-plugin/badge.svg?style=flat)](https://maven-badges.herokuapp.com/maven-central/com.github.davidmoten/git-properties-maven-plugin)

[![codecov](https://codecov.io/gh/davidmoten/git-properties-maven-plugin/branch/master/graph/badge.svg)](https://codecov.io/gh/davidmoten/git-properties-maven-plugin)

A maven plugin that
* writes a file to the artifact classpath (by default) containing the current git commit hash (long and short) and the timestamp of that commit
* sets properties that can be used in the pom.xml (e.g. in ) but only if the plugin is bound to the **initialize** phase (which is the default)
* relies on the existence of the git binary on the current path

**Status:** *deployed to Maven Central*
## Usage

Add this fragment to the build/plugins section in your pom.xml:

```xml

com.github.davidmoten
git-properties-maven-plugin
VERSION_HERE


properties

properties


```
The above fragment will add a `git.properties` file to the generated artifact classpath (`${project.build.outputDirectory}`) when you run `mvn clean install`. The file looks like this:

```
git.commit.hash=b49337feb3260a67bc4b5b188e4d0d3f17408150
git.commit.hash.short=b49337f
git.commit.timestamp=20200116220611
git.commit.timestamp.format=yyyyMMddHHmmss
git.commit.timestamp.format.timezone=UTC
git.commit.timestamp.iso8601=2020-01-16T22:06:11Z
git.commit.timestamp.iso8601.format=yyyy-MM-dd'T'HH:mm:ssX
git.commit.timestamp.epoch.ms=1579212371000

```

If you are generating a jar or war artifact then the file will a resource at the root of the classpath (`/git.properties`).

The same properties are set for use in the pom.xml also so you can use `${git.commit.hash.short}` for instance anywhere in the pom.xml.

### Overriding defaults
You can override the default location, filename, and timestamp formats like this:

```xml

com.github.davidmoten
git-properties-maven-plugin
VERSION_HERE


write-properties

properties




${project.build.outputDirectory}/git
commit.properties
yyyy-MM-dd HH:mm:ssZ
AEST

```
### Using properties set by git-properties-maven-plugin
Because the plugin is bound by default to the **initialize** phase the properties it sets (with the same key names and values as in the `git.properties` file) are available for use in the pom.xml. For example you can set the to use the short git commit hash and the commit timestamp as well:

```xml
${project-artifactId}-${project.version}-${git.commit.hash.short}-${git.commit.timestamp}
```