|
I basically need access to the timestamp to create a JAR manifest entry similar to the following:
Build-date: 20051231-1841 Ideally we should be able to format the timestamp, but that is not absolutely necessary. P.S: I'm using a custom manifest template (not as part of pom.xml) and use filtering to prepare the manifest file. E.g. My template looks like: Package: ${product.name} I have created a patch that adds a set of default expressions to maven. The following list of expressions are currently supported in the patch.
${mvn.timestamp} - A simple timestamp with "yyyyMMddHHmmss" as the date format. TODO: Possible future enhancement/support: NOTE: If anyone has any suggestions or ideas for other default expressions or improvements I'd very much like to hear it. I just realized that the patch I attached previously was intended for another issue. Here here is the correct patch (maven-core_defaultExpressions.patch)
There are now several plugins to add information to properties. The buildinfo plugin at Mojo for example.
What happened to the buildinfo plugin? It was in the sandbox and now it disappeared.
Look at the hoops someone else went through: http://www.gadberry.com/aaron/2007/05/28/inject-build-time-timestamp-property-using-maven/ I notice his caveat that you have to build twice, all for a timestamp. It's a shame the fix won't be included until 2.1. I downloaded head of 2.1 and used mvn.timestamp and didn't seem to filter properly still. How is this issue fixed? It doesn't work for me.
I suspect this issue is closed because there are alternatives, albeit inferior IMO. In that case the resolution should not be 'fixed' but 'wontfix', otherwise people will expect this to work when it doesn't. buildinfo is at: http://mojo.codehaus.org/buildnumber-maven-plugin/
IMHO there should be a proper description showing how this can be done before this issue can be considered 'fixed'. the buildnumber plugin exposes by default 2 properties: ${buildNumber} and ${timestamp}. You can use these anywere in the pom, for example pass them as a parameter to a custom mojo that writes them to your custom property file if you'ld like.
Alternatively just add them to the manifest with something like this: <plugin> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifestEntries> <svnrevision>${buildNumber}</svnrevision> <buildDate>${timestamp}</buildDate> </manifestEntries> </archive> </configuration> </plugin> Unfortunately, the buildnumber plugin works only with SVN. Maven supports a greater breadth of SCM implementations, which I believe should be considered here.
How is this issue fixed? In version 2.0.9 isn't added any timestamp built.in propertiy...
I agree with others who state that the other suggest solutions are adequate. They are not.
The timestamp the buildnumber plugin provides is an "epoch" integer value. The resulting manifest then looks like this: Manifest-Version: 1.0 Note the "buildDate" value. There is no way to modify that format. The output of the timestamp property does not have the formatting capabilities of the buildNumber property. In fact, here is the code from the plugin that sets the value: String timestamp = String.valueOf( now.getTime() ); Exposing a date-time property within Maven itself that can be used within the jar plugin configuration section would be preferred and should be easy. See
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
app.builtOn=${timestamp}
app.scmVersion=${scm.currentRevision}
I can use $Revision$ or $LastChangedRevision$ because I would have to remember to modify and commit that properties file before building.