Embed git-describe, date and time in a build during compilation in eclipse

I am using an external builder feature in eclipse to call a bash script that will autogenerate BuildInfo.java class for my project (I’ve looked here on stackoverflow for a way to embed git-describe and date into an eclipse (non-ant!) build, but couldn’t find any), my the script looks like this:

#!/bin/bash

VERSION=$(git describe --tag)
DATE=$(date "+%Y-%m-%d")
TIME=$(date "+%H:%M")

echo "Version $VERSION, built on $DATE $TIME"

cat > src/com/bla/bla/BuildInfo.java <<DELIM
package com.bla.bla;

// Auto-generated, triggered by project build
public class BuildInfo {
    public static String version = new String("$VERSION");
    public static String date = new String("$DATE");
    public static String time = new String("$TIME");
}
DELIM

I configure the external builder to execute every build (even automatic ones) before the java/android builders. This scheme indeed works fine when I do full project clean, however when I update another file, even though Eclipse does execute my external builder, and BuildInfo class is indeed being regenerated, Eclipse still uses old cached version of the class for the final result, so I see old info, which can sometimes be worse than not having build info at all.

  • swipe activity to change another activity in android and show multiple Activity in a singleview?
  • How does git push work with android's repo tool?
  • Generating android build with jenkins.Creating .apk files
  • Eclipse Android and gitignore
  • Import existing Android project in Eclipse: no gen source folder?
  • Android Crashlytics Eclipse: what to commit to git?
  • Do you have any idea how I can tell Eclipse this file is generated and it shouldn’t cache it at all, but load it from the disc after my external builder is done and before java builder? Is there any other elegant solution to get that data into the build?

    Thank you!

  • How Do I Get Back Untracked Files I Stashed with Git?
  • Finding what git commit some code spawned from
  • How do I reconnect a moved git repository with it's original project in Egit?
  • Docker-client Java API : The server failed to respond with a valid HTTP response
  • Android+Eclipse project sharing via SVN?
  • Git won't stop tracking eclipse java .recommenders
  • One Solution collect form web for “Embed git-describe, date and time in a build during compilation in eclipse”

    In Eclipse you can specify the resources that have changed after a custom built-tool ran.

    Go to your built-tool select Edit switch to the Refresh-Tab.
    Select Refresh resources upon completion, Specific resources… and add your auto-generated BuildInfo.java.

    Git Baby is a git and github fan, let's start git clone.