Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/davidmoten/git-properties-maven-plugin
- Owner: davidmoten
- License: apache-2.0
- Created: 2020-01-15T22:06:14.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-04T05:21:39.000Z (7 months ago)
- Last Synced: 2024-04-04T06:28:59.323Z (7 months ago)
- Language: Java
- Homepage:
- Size: 51.8 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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*
## UsageAdd 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}
```