Maven 2 & 3

built-in property containing current timestamp

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.0.1
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Complexity:
    Intermediate
  • Patch Submitted:
    Yes
  • Number of attachments :
    2

Description

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

Issue Links

Activity

Hide
Piotr Bzdyl added a comment -

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.

Show
Piotr Bzdyl added a comment - 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.
Hide
Chris Hagmann added a comment -

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}
...
...

Show
Chris Hagmann added a comment - 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} ... ...
Hide
Sharmarke Aden added a comment -

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.

Show
Sharmarke Aden added a comment - 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.
Hide
Sharmarke Aden added a comment -

I just realized that the patch I attached previously was intended for another issue. Here here is the correct patch (maven-core_defaultExpressions.patch)

Show
Sharmarke Aden added a comment - I just realized that the patch I attached previously was intended for another issue. Here here is the correct patch (maven-core_defaultExpressions.patch)
Hide
Jason van Zyl added a comment -

There are now several plugins to add information to properties. The buildinfo plugin at Mojo for example.

Show
Jason van Zyl added a comment - There are now several plugins to add information to properties. The buildinfo plugin at Mojo for example.
Hide
Paul Sundling added a comment -

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.

Show
Paul Sundling added a comment - 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.
Hide
Matthijs Wensveen added a comment -

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.

Show
Matthijs Wensveen added a comment - 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.
Hide
Arnout Engelen added a comment -

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'.

Show
Arnout Engelen added a comment - 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'.
Hide
Jorg Heymans added a comment -

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>

Show
Jorg Heymans added a comment - 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>
Hide
Paul Benedict added a comment -

Unfortunately, the buildnumber plugin works only with SVN. Maven supports a greater breadth of SCM implementations, which I believe should be considered here.

Show
Paul Benedict added a comment - Unfortunately, the buildnumber plugin works only with SVN. Maven supports a greater breadth of SCM implementations, which I believe should be considered here.
Hide
Marco Noto added a comment -

How is this issue fixed? In version 2.0.9 isn't added any timestamp built.in propertiy...

Show
Marco Noto added a comment - How is this issue fixed? In version 2.0.9 isn't added any timestamp built.in propertiy...
Hide
Steve Gilbert added a comment -

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.

Show
Steve Gilbert added a comment - 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.
Hide
Steve Gilbert added a comment -

MNG-2562 states this is fixed in 2.0.10 but there is no explanation how it was fixed.

Show
Steve Gilbert added a comment - MNG-2562 states this is fixed in 2.0.10 but there is no explanation how it was fixed.
Hide
Paul Benedict added a comment -

See MNG-3718 on how it was implemented.

Show
Paul Benedict added a comment - See MNG-3718 on how it was implemented.

People

Vote (25)
Watch (16)

Dates

  • Created:
    Updated:
    Resolved: