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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How To Build Self-Hosted RSS Feed Reader Using Spring Boot and Redis
  • How to Implement Two-Factor Authentication in A Spring Boot OAuth Server? Part 2: Under the Hood
  • Leveraging Marqeta to Build a Payment Service in Spring Boot
  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4

Trending

  • Searching Kafka Without an Index: Lessons From Building Message Search for Kafdrop
  • Delta Lake UniForm to Snowflake: Cross-Platform Table Access Without a Second Copy
  • Beyond the Endpoint: How Agent Cards Enable Discovery, Interoperability, and Trust
  • Google Cloud KMS vs. AWS KMS: Java Encryption Guide

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Frameworks
  4. Micronaut Mastery: Add Build Info to an Info Endpoint

Micronaut Mastery: Add Build Info to an Info Endpoint

Let's look at how to add build info to a Micronaut info endpoint to get information about what's currently deployed for monitoring purposes.

By 
Hubert Klein Ikkink
·
Aug. 21, 18 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
6.3K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Micronaut has some built-in management endpoints to get information, a list of beans, health checks and more. To enable the endpoints we must add the dependency io.micronaut:management to our application. Then we can add configuration properties to enable the different endpoints. The /info endpoint gathers information from several sources with properties. If we want to add build information we must create a file build-info.properties with information and Micronaut will automatically add the properties from the file to the /info endpoint.

We can choose how we want to create the build-info.properties file. The location is configurable via Micronaut application configuration properties, but the default location is on the classpath at META-INF/build-info.properties. To make life easy for us we reuse the Gradle task from the Spring Boot Gradle plugin to create the build-info.properties file.

In the following example build file we add a build script classpath dependency on the Spring Boot Gradle plugin. This will add the BuildInfo class to our Gradle build file. Next we create a new task buildInfo using the BuildInfo type and we set the destination directory to the resources/main/META-INF directory in the project build directory. This is the default location that Micronaut uses to read the properties for the /info endpoint.

// File: build.gradle
buildscript {
   ...
   dependencies {
       ...
       classpath "org.springframework.boot:spring-boot-gradle-plugin:2.0.4.RELEASE"
       ...
    }
}
...
dependencies {
    ...
    // Add management endpoint support.
    runtime "io.micronaut:management"
    ...
}
...
import org.springframework.boot.gradle.tasks.buildinfo.BuildInfo

task buildInfo(type: BuildInfo) {
    description = 'Generates build-info.properties file.'

    group = BasePlugin.BUILD_GROUP

    destinationDir = new File(sourceSets.main.output.resourcesDir, 'META-INF')

    properties {
        time = null // Otherwise task is never up-to-date
        artifact = shadowJar.baseName

        // Extra properties that will be added to build-info.properties.
        additionalProperties = [
                by: System.properties['user.name'],
                operatingSystem: "${System.properties['os.name']} (${System.properties['os.version']})",
                continuousIntegration: System.getenv('CI') ? true: false,
                machine: InetAddress.localHost.hostName,
        ]
    }
}
classes.dependsOn buildInfo
...

In our application configuration we enable the /info endpoint:

# File: src/main/resources/application.yml
...
endpoints:
  info:
    enabled: true
    sensitive: false
...

We start our Micronaut application and invoke the /info endpoint and we get the following data:

{
    "build": {
        "artifact": "micronaut-sample",
        "by": "mrhaki",
        "continuous-integration": "false",
        "group": "mrhaki.micronaut",
        "machine": "mrhaki.fritz.box",
        "name": "micronaut-sample",
        "operating-system": "Mac OS X (10.13.6)",
        "version": "1.0.1"
    }
}

Written with Micronaut 1.0.0.M4.

Build (game engine) Spring Framework Spring Boot

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 Self-Hosted RSS Feed Reader Using Spring Boot and Redis
  • How to Implement Two-Factor Authentication in A Spring Boot OAuth Server? Part 2: Under the Hood
  • Leveraging Marqeta to Build a Payment Service in Spring Boot
  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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