Issue Details (XML | Word | Printable)

Key: MNG-1832
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Michal Stochmialek
Votes: 25
Watchers: 16
Operations

If you were logged in you would be able to see more operations.
Maven 2

built-in property containing current timestamp

Created: 14/Dec/05 02:26 AM   Updated: 20/Aug/08 01:46 PM
Component/s: None
Affects Version/s: 2.0.1
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Text File maven-archiver_pomDelete.patch (4 kB)
2. Text File maven-core_defaultExpressions.patch (12 kB)

Issue Links:
Related
 
dependent
 

Complexity: Intermediate
Patch Submitted: Yes


 Description  « Hide
Current timestamp (time or date) is often used while filtering resources or creating manifest in ant builds. There is no equivalent in maven.

 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Piotr Bzdyl added a comment - 16/Dec/05 01:01 AM
It would be very helpful in filling some properties files to get built-time at the artifact runtime to identify the version. It would be also helpful to have property with the current checkout revision (ie. ${scm.currentRevision}). Then I could use in the resources.properties:
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.


Chris Hagmann added a comment - 31/Dec/05 07:24 PM
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}
Build-Date: ${timestamp}
Specification-Title: ${product.name}
Specification-Version: ${product.specification.version}
Specification-Vendor: ${pom.organization.name}
Implementation-Title: ${product.name}
Implementation-Version: ${pom.version}
Implementation-Vendor: ${pom.organization.name}
...
...


Sharmarke Aden added a comment - 17/May/06 04:36 PM
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.
${mvn.timestamp.DATE_FORMAT} - A timestamp expression which includes a custom date format pattern (i.e ${mvn.timestamp.yyyy-MM-dd}).
${mvn.build.version} - The build version of maven from "META-INF/maven/org.apache.maven/maven-core/pom.properties" in maven-core.jar
${mvn.build.date} - The date maven was built. Please note that the build date will be inferred from the "builtOn" property in "META-INF/maven/org.apache.maven/maven-core/pom.properties" which is located in maven-core.jar
${mvn.pom.dir} - The name of the parent directory of the pom.xml file. Note that the directory name value does not include the path of the directory.
${mvn.pom.build} - The current build number for the project. To use this variable a "mvn.pom.build" property should be present in the project's pom.properties file. If the pom.properties file doesn't exist a stub pom.properties file will be created containing '1' as the default build number. If "mvn.pom.build" is passed in as a system property the system property value will be used instead of the build number in the pom.properties. Also note that the responsibility of incrementing the build number lies with the developer. Ideally we want the continuous integration system to manage build numbers.
${mvn.pom.date} - The date of the build. To use this variable a "mvn.pom.date" property should be present in the project's pom.properties file. If the pom.properties file doesn't exist a stub pom.properties file will be created with today's date as the default build date. Please note that if "mvn.pom.date" is passed in as a system property the system property value will be used instead of the build date in the pom.properties.

TODO: Possible future enhancement/support:
${mvn.scm.revision} - Current revision of the project. I'm not sure of the feasibility of doing this for any SCM other than Subversion and Bazaar. Subversion and Bazaar have the concept of "global revisions" while CVS doesn't. We need to investigate if ClearCase, Perforce, and StarTeam support concept similar to global revision number and how to integrate that with SCM.

NOTE:
This patch is dependent on a patch I submitted to the maven-archive component: http://jira.codehaus.org/browse/MNG-2301

If anyone has any suggestions or ideas for other default expressions or improvements I'd very much like to hear it.


Sharmarke Aden added a comment - 07/Jun/06 06:36 PM
I just realized that the patch I attached previously was intended for another issue. Here here is the correct patch (maven-core_defaultExpressions.patch)

Jason van Zyl added a comment - 01/Jun/07 04:08 PM
There are now several plugins to add information to properties. The buildinfo plugin at Mojo for example.

Paul Sundling added a comment - 21/Jun/07 09:17 PM
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.


Matthijs Wensveen added a comment - 20/Feb/08 05:07 AM
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.

Arnout Engelen added a comment - 22/Feb/08 10:35 AM
buildinfo is at: http://mojo.codehaus.org/buildnumber-maven-plugin/ . I don't quite see how I can use that to add a timestamp to a properties file though.

IMHO there should be a proper description showing how this can be done before this issue can be considered 'fixed'.


Jorg Heymans added a comment - 11/Mar/08 07:55 AM
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>

Paul Benedict added a comment - 11/Mar/08 02:47 PM
Unfortunately, the buildnumber plugin works only with SVN. Maven supports a greater breadth of SCM implementations, which I believe should be considered here.

Marco Noto added a comment - 22/Apr/08 05:46 AM
How is this issue fixed? In version 2.0.9 isn't added any timestamp built.in propertiy...

Steve Gilbert added a comment - 20/Aug/08 08:56 AM
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
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: gilberts2
Build-Jdk: 1.4.2_15
Implementation-Title: a-code-module
Implementation-Version: 1.0-SNAPSHOT
Implementation-Vendor-Id: srg
Implementation-Build: 65
buildDate: 1219240079087

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() );
project.getProperties().put( timestampPropertyName, timestamp );

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.


Steve Gilbert added a comment - 20/Aug/08 09:00 AM
MNG-2562 states this is fixed in 2.0.10 but there is no explanation how it was fixed.

Paul Benedict added a comment - 20/Aug/08 01:46 PM
See MNG-3718 on how it was implemented.