mjhugo / grails-build-info

Provides a Grails controller/view that display basic information about a deployed WAR file
Other
8 stars 14 forks source link

Grails 3.+ Support #15

Open mxgross opened 8 years ago

mxgross commented 8 years ago

Grails 3.+ Support would be nice.

rlovtangen commented 8 years ago

Hi @mexx91,

I have started to take a look at it. Evaluating whether to leverage existing Gradle plugins for retrieving scm info. One plugin I have tried is https://github.com/nemerosa/versioning. Install by adding the following to build.gradle:

plugins {
   id 'net.nemerosa.versioning' version '1.6.2'
}

Then scm and other info can be added to e.g. META-INF/MANIFEST.MF with e.g.:

war {
    manifest {
        attributes(
            'Built-By': System.properties['user.name'],
            'Java-Version': "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})".toString(),
            'Build-Scm-Revision': versioning.info.commit,
            'Build-Scm-Branch': versioning.info.branch,
            'Build-Time': new Date().format("yyyy-MM-dd'T'HH:mm:ss"),
            'Project-Name': project.name,
            'Project-Version': project.version,
        )
    }
}

Maybe it's better to write this information to META-INF/grails.build.info, haven't looked into how to do that yet.

Maybe there are better alternatives to nemerosa/versioning. One issue it has is that project root must be the top folder, i.e. the one with .git. A workaround is to add a settings.gradle if the grails app is not in the top folder.

This plugin then only needs to include code for displaying this information, i.e. BuildInfoController.

ghost commented 7 years ago

Any updates on Grails 3 support?

rlovtangen commented 7 years ago

My own needs lately has been limited to getting the scm revision from the manifest (stored by nemerosa versioning), which was easy enough with:

def inputStream = servletContext.getResourceAsStream("/META-INF/MANIFEST.MF");
def manifest = new Manifest(inputStream)
return manifest.mainAttributes.getValue('Build-Scm-Revision')

Would be nice with a BuildInfoController, though. At the moment I have to peek inside the war file to see all attributes saved by nemerosa versioning. Maybe use a prefix for the manifest attributes and list all attributes with said prefix from BuildInfoController? Or just list all manifest attributes? Not even sure if manifest is best place to store the attributes, but haven't got time to look into writing to META-INF/grails.build.info or some other file, yet.

Any thoughts? Write to META-INF/MANIFEST.MF, META-INF/grails.build.info or some other file? Utilize nemerosa versioning and require user to add the war.manifest.attributes-block or similar to build.gradle? How to control which attributes are listed by BuildInfoController?

rlovtangen commented 7 years ago

Here's another alternative: http://guides.grails.org/adding-commit-info/guide/index.html