I want my Android application to know at runtime when the application was built. I am new to Gradle, but it seems very flexible and I think it might be possible to achieve this without any external helper programs or token replacement.
My idea was to compute a timestamp string in some sort of a Gradle pre-build task. Then I would like to pass this string as a system property to the Java application. For example:
def timestamp = ...
systemProperty 'my.build.timestamp' timestamp
And then retrieve the timestamp at runtime in Java:
String iWasBuiltAt = System.getProperty("my.build.timestamp");
How would I go about writing the neccesary Gradle code to achieve this? More specifically, where/how do invoke my custom task and is it possible to add system properties in such a way as described above.