How to get Git information in Java Application

In this post, we are going to see how to get the GIT information in a Java application.

To do that, we have to use the maven-git-commit-id-plugin plugin. Refer it @maven-git-commit-id-plugin

Now let’s see how we gonna do that.

1. Include the below plugin configuration in your Maven POM file.

                            <dateFormat>MM/dd/yyyy HH:mm:ss Z</dateFormat>

2. Then do maven install (mvn install). You can set the verbose as false if you don’t want to see the git commit id plugin log.

3. After the build is done, then go to target/classes folder. You will see contains the git related information. You can read this properties file in your application and use it.

Sample code is given below.

 static Properties properties = new Properties();
        try (InputStream is = this.class.getClassLoader()
                .getResourceAsStream("")) {
        catch (IOException io) {

File Name:
File Path: /target/classes/
Sample properties are given below.

#Generated by Git-Commit-Id-Plugin
#Fri Nov 17 09:49:44 EST 2017
git.commit.message.full=Update Dockerfile
git.commit.message.short=Update Dockerfile
git.commit.time=09/19/2017 18\:25\:16 -0400
git.dirty=true 09\:49\:44 -0500

Refer my code @java-rest-docker

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s