Ruby Programmer/Developer

George Armhold's Blog

Data-driven webapps built with Ruby, Java & Wicket

Adding Git SHAs to Wicket Pages Automatically

If you have a non-trivial project, it’s handy to be able to tell what code was used to build a particular release once it’s been deployed. Especially if you’ve recently discovered the joys of branching and merging with Git.

Here’s a handy way to add a Git SHA to all your app’s pages via Wicket and Maven.


First, we’ll use the exec-maven-plugin to create a file for us. Add this to the section in your pom.xml:

            <argument>--pretty=format:gitsha=%H %ci</argument>

This will create a file containing the Git SHA, along with the commit timestamp whenever your code is compiled. You can learn how to further customize this here.

Wicket Application Subclass

Now we’ll need to read in the file when our application starts up.

public class Application extends WebApplication
    private String gitSHA;

    public AppgravityApplication()
        java.util.Properties props = new java.util.Properties();
            gitSHA = props.getProperty("gitsha");
  "gitsha: " + gitSHA);
        catch (IOException e)
            gitSHA = "unknown";

    public String getGitSHA()
        return gitSHA;

Wicket WebPage Subclass

Now we’ll create a WebPage subclass that renders the Git SHA into a tag when the page is rendered.

public abstract class MyPage extends WebPage
    protected void onBeforeRender()
        Label metaGitSHA = new Label("metaGitSHA", "");
        metaGitSHA.add(new AttributeModifier("content", Model.of(((Application) getApplication()).getGitSHA())));

You’ll want to extend MyPage for each of your pages. You’ll need to add the placeholder meta tag to each of your HTML pages like this:

    <meta wicket:id="metaGitSHA" id="metaGitSHA" name="metaGitSHA" content=""/>

And you’re done!