Get git information in your CDI application easily thanks to DeltaSpike and git-commit-id-plugin

Having SCM information in the project is really interesting to dump them at startup for instance.

There are several ways to do it.

One easy is to use templating-maven-plugin and filter a .java with these information but it has several drawbacks:

  • IDE can be lost with these files (not compiling for instance)
  • You link sources and build tool
  • You didn’t solve how to get all the information (need another plugin)

An alternative is to use git-commit-id-plugin. This plugin fill several properties:
git.commit.message.full=initial import\n
git.commit.message.short=initial import Manni-Bucau Manni-Bucau
git.commit.time=08.07.2014 @ 21\:10\:47 CEST @ 21\:29\:34 CEST

By default these information are not dumped anywhere. To get it dumped you need to configure a bit the plugin:


Generating in target/classes allows to get it in the classloader of the application which can be very interesting!

If you use CDI you surely use Apache DeltaSpike. If you depend at least on core modules (api and impl) which is likely the case you can just add a single class to make these properties available as injection value:

import org.apache.deltaspike.core.api.config.PropertyFileConfig;

public class GitPropertyFile implements PropertyFileConfig {
    public String getPropertyFileName() {
        return "";

Then you can just get git metadata injected as usual:

public class GitMetaData {
    @ConfigProperty(name = "git.remote.origin.url")
    private String gitUrl;

    @ConfigProperty(name = "")
    private String gitCommitId;

    @ConfigProperty(name = "git.branch")
    private String gitBranch;

    public void dump() {
        // do dump of metadata

Here is a full sample project:


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