Having Gradle Note Your Build Info

Managing Java server code you’ll employ a lot of monitoring tools, standard and often custom. But in addition to runtime info, I often want to know the build information of a process. What version is it? What is it dependent on? Who built it? When? Things like that. Ideally you want this reported in a consistent format so your monitoring tools can incorporate it.

Working somewhere that doesn’t yet have a standard for this, I wrote a minimal gradle plugin that gathers base information and creates a JSON file containing it. So, each build, this info can be branded into the code and then retrieved programmatically. For example, my RESTful servers just hang the file off a standard end point.

At this point the file looks something like:

{
    "project.name": "super-server",
    "project.version": "1.0.5",
    "builder": "jenkins",
    "build.date": "2015-12-30T20:13:06+0000",
    "java.vendor": "Oracle Corporation",
    "java.version": "1.8.0_60",
    "source.compatibility": "1.8",
    "target.compatibility": "1.8",
    "dependencies": [
        "slf4j-jdk14-1.7.13.jar",
        "jetty-server-9.3.2.v20150730.jar",
        "jetty-webapp-9.3.2.v20150730.jar",
        "websocket-server-9.3.2.v20150730.jar",
        "websocket-servlet-9.3.2.v20150730.jar",
        "javax.servlet-api-3.1.0.jar",
        "jetty-http-9.3.2.v20150730.jar",
        "jetty-io-9.3.2.v20150730.jar"
    ]
    "custom": {
        "branch": "dev"
    }
}

The plugin is dead simple to use, I just make gradle’s processResources task depend on it. You can take a look at the project on Github.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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