DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How To Build Web Service Using Spring Boot 2.x
  • How to Activate New User Accounts by Email
  • How to Import the Gradle Spring Boot Application in Eclipse? | Spring Boot Tutorial [Video]
  • Bing Maps With Angular in a Spring Boot Application

Trending

  • Liquid Glass, Material 3, and a Lot of Plumbing
  • Why Your Test Automation Is Always Behind the Code And the Architecture That Fixes It
  • Implementing Observability in Distributed Systems Using OpenTelemetry
  • Skills, Java 17, and Theme Accents
  1. DZone
  2. Coding
  3. Frameworks
  4. Spring Sweets: Add Git Info to Info Endpoint

Spring Sweets: Add Git Info to Info Endpoint

A simple change to the Gradle configuration can enhance your Spring Boot information endpoint with extra Git information.

By 
Hubert Klein Ikkink user avatar
Hubert Klein Ikkink
·
Dec. 22, 16 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
11.6K Views

Join the DZone community and get the full member experience.

Join For Free

With Spring Boot Actuator, we get some endpoints that display information about our application. One of the endpoints is the /info endpoint. If our project uses Git, we can add information about Git to the /info endpoint. By default, Spring Boot will look for a file git.properties in the classpath of our application. The file is a Java properties file with keys that start with git. and have values like the branch name, commit identifier, and commit message.

Spring Boot uses this information, and when we request the /info endpoint, we get a response with the information. This can be very useful to check the Git information that was used to build the application. To create the git.properties file, we can use a Gradle (or Maven) plugin that will do the work for us.

In the following example, we use the Gradle plugin to generate the git.properties file for our project. The Gradle Git properties plugin is added in the plugins configuration block. The plugin adds a Gradle extension gitProperties that can be used to customize the output in git.properties. We could even change the location (but we keep it to the default location build/resources/main/git.properties).

// File: build.gradle
plugins {
    id 'org.springframework.boot' version '1.4.2.RELEASE'
    // Add Git properties plugin.
    id 'com.gorylenko.gradle-git-properties' version '1.4.17'
}

// Customize Git properties plugin.
gitProperties {
    // Change date format in git.properties file.
    dateFormat = "yyyy-MM-dd HH:mm:ssZ"
    dateFormatTimeZone = 'GMT'
}

That is all we need to do. The Git properties plugin generates the git.properties file that is need by Spring Boot. Let's run our application and send a request for the /info endpoint:

$ http -b localhost:8080/info
{
    "git": {
        "branch": "feature/dsl-hapi",
        "commit": {
            "id": "511d269",
            "time": "2016-12-15 12:28:20+0000"
        }
    }
}
$

We can even show more information by changing the Spring Boot configuration property management.git.info.mode. The default value is SIMPLE, but we can also use the value FULL. Then, we get the Git commit message and user details. We can set the configuration property in different ways for our Spring Boot application (for example, in application.yml, Java system property or environment variable). In our example, we add a Java system property to the Gradle bootRun task:

// File: build.gradle
...
bootRun {
    systemProperty 'management.info.git.mode', 'FULL'
}
...

We execute the bootRun task and send a new request for the /info endpoint:

$ http -b localhost:8080/info
{
    "git": {
        "branch": "feature/dsl-hapi",
        "commit": {
            "id": "511d2693cbabc34449f838bf856fa2b9989cbca6",
            "id.abbrev": "511d269",
            "message": {
                "full": "Enable Codenarc checks for integration test code",
                "short": "Enable Codenarc checks for integration test code"
            },
            "time": "2016-12-15 12:28:20+0000",
            "user": {
                "email": "mrhaki@server",
                "name": "Hubert Klein Ikkink"
            }
        }
    }
}
$

This time, we see more information about Git.

Written with Spring Boot 1.4.2.RELEASE.

Spring Framework Git Spring Boot application Property (programming) Gradle

Published at DZone with permission of Hubert Klein Ikkink. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How To Build Web Service Using Spring Boot 2.x
  • How to Activate New User Accounts by Email
  • How to Import the Gradle Spring Boot Application in Eclipse? | Spring Boot Tutorial [Video]
  • Bing Maps With Angular in a Spring Boot Application

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook