Skip to content

How to generate git.properties file

Somnath Musib edited this page Mar 27, 2021 · 2 revisions

Introduction

The git.properties file contains various information related to the GIT repository. The following is a sample git.properties file:

git.branch = main,
git.build.host = DESKTOP-VBHX979,
git.build.time = 2021-03-27T19:30:23+0530,
git.build.user.email = abc@gmail.com,
git.build.user.name = abc,
git.build.version = 0.0.1-SNAPSHOT,
git.closest.tag.commit.count = ,
git.closest.tag.name = ,
git.commit.id = 3f436f914a8df23f423300cd285ef2f730bd5024,
git.commit.id.abbrev = 3f436f9,
git.commit.id.describe = 3f436f9-dirty,
git.commit.id.describe-short = 3f436f9-dirty,
git.commit.message.full = Added custom health indicator,
git.commit.message.short = Added custom health indicator,
git.commit.time = 2021-03-27T17:01:00+0530,
git.commit.user.email = abc@gmail.com,
git.commit.user.name = abc,
git.dirty = true,
git.local.branch.ahead = 0,
git.local.branch.behind = 0,
git.remote.origin.url = git@github.com:spring-boot-in-practice/repo.git,
git.tags = ,
git.total.commit.count = 55

In this article, we'll discuss how to generate this file in a Maven project

Maven Plugin

You can generate a Spring Boot Maven project or a plain Maven project and add the git-commit-id-plugin plugin in the plugins section of the pom.xml file:

<plugin>
  <groupId>pl.project13.maven</groupId>
  <artifactId>git-commit-id-plugin</artifactId>
  <executions>
    <execution>
      <id>get-the-git-infos</id>
      <goals>
        <goal>revision</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
    <prefix>git</prefix>
    <verbose>false</verbose>
    <generateGitPropertiesFile>true</generateGitPropertiesFile>
    <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
    <format>json</format>
    <gitDescribe>
      <skip>false</skip>
      <always>false</always>
      <dirty>-dirty</dirty>
    </gitDescribe>
  </configuration>
</plugin>

if you run the mvn install command, the git-commit-id-plugin generates the git.properties file inside the target\classes folder.

Clone this wiki locally