Maven 2 & 3
  1. Maven 2 & 3
  2. MNG-2562

expose current time as a property for POM interpolation

    Details

    • Complexity:
      Intermediate
    • Number of attachments :
      0

      Description

      it is useful to have the current time, for example to write out a manifest entry for the build time or to filter into another file.

      I'm not sure of the best way to make the format of the time configurable - perhaps another POM element/property.

      See the related issue for a current example of how this can be done, but it would be nice to have a built-in.

        Issue Links

          Activity

          Hide
          Barend Garvelink added a comment -

          Brett Porter wrote:

          I'm not sure of the best way to make the format of the time configurable - perhaps another POM element/property.

          I think this issue should focus on merely adding the timestamp property, I think formatting is much better handled by MNG-3374. Reason: I may want to use multiple formats for the same timestamp, for example, UTC and ISO-8601 in the JAR manifest and Europe/Amsterdam with a custom pattern in a common footer JSP.

          wrt reactor builds: is it desirable (or even possible) to add the timestamp for every sub-module in addition to the timestamp the build was started? The naming scheme could use Maven coordinates:

          build.timestamp #time the build was started
          build.timestamp.groupId:module1 #time module1 was started
          Show
          Barend Garvelink added a comment - Brett Porter wrote: I'm not sure of the best way to make the format of the time configurable - perhaps another POM element/property. I think this issue should focus on merely adding the timestamp property, I think formatting is much better handled by MNG-3374 . Reason: I may want to use multiple formats for the same timestamp, for example, UTC and ISO-8601 in the JAR manifest and Europe/Amsterdam with a custom pattern in a common footer JSP. wrt reactor builds: is it desirable (or even possible) to add the timestamp for every sub-module in addition to the timestamp the build was started? The naming scheme could use Maven coordinates: build.timestamp #time the build was started build.timestamp.groupId:module1 #time module1 was started
          Hide
          Paul Benedict added a comment -

          Can property names include colons? I am referring to last example.

          Show
          Paul Benedict added a comment - Can property names include colons? I am referring to last example.
          Hide
          Shane Isbell added a comment -

          Bug fix here: https://svn.apache.org/repos/asf/maven/sandbox/branches/MNG-3536

          This is part of a rewrite of the interpolation code.

          Show
          Shane Isbell added a comment - Bug fix here: https://svn.apache.org/repos/asf/maven/sandbox/branches/MNG-3536 This is part of a rewrite of the interpolation code.
          Hide
          Benjamin Bentmann added a comment -

          I'm not sure of the best way to make the format of the time configurable

          I like the idea proposed by Sharmarke Aden in MNG-1832: $

          {mvn.timestamp.DATE_FORMAT}

          , i.e. simply appending the desired format to the propery base name. This allows users to easily choose the format for their respective use case.

          The only thing that might be missing is the locale. Could perhaps be integrated like this: {{$

          {mvn.tstamp-lang,country,variant.DATE_FORMAT}

          }} which should be straightforward to parse.

          Show
          Benjamin Bentmann added a comment - I'm not sure of the best way to make the format of the time configurable I like the idea proposed by Sharmarke Aden in MNG-1832 : $ {mvn.timestamp.DATE_FORMAT} , i.e. simply appending the desired format to the propery base name. This allows users to easily choose the format for their respective use case. The only thing that might be missing is the locale. Could perhaps be integrated like this: {{$ {mvn.tstamp-lang,country,variant.DATE_FORMAT} }} which should be straightforward to parse.
          Hide
          Paul Benedict added a comment -

          If this is fixed, can someone comment on the resolution? What was chosen?

          Show
          Paul Benedict added a comment - If this is fixed, can someone comment on the resolution? What was chosen?
          Hide
          Wendy Smoak added a comment -

          A user asked about this on irc:

          benson0: I'm lost in the maze of MNG-3718. Can someone just tell me the ${} to access a readable build date in 2.1.0? None of the syntaxes mentioned in the jiras seem to be right.
          jason: $

          {build.timestamp}

          I can't find it anywhere in the site, however grep does turn up a mention in maven-project-spec.tex as well as the code/tests.

          Show
          Wendy Smoak added a comment - A user asked about this on irc: benson0: I'm lost in the maze of MNG-3718 . Can someone just tell me the ${} to access a readable build date in 2.1.0? None of the syntaxes mentioned in the jiras seem to be right. jason: $ {build.timestamp} I can't find it anywhere in the site, however grep does turn up a mention in maven-project-spec.tex as well as the code/tests.
          Hide
          Matthew McCullough added a comment -

          Per Wendy's last comment captured from benson0 and Jason, I'm after the same thing. I have a .properties file that is part of our filtered resources that I want to put the timestamp into. If I put $

          {build.timestamp} into the .properties file it isn't replaced. I see this interpolation in the source of the 2.2.0 branch of Maven, which we are using, in the file maven-project/src/main/java/org/apache/maven/project/interpolation/BuildTimestampValueSource.java

          Even though I couldn't get it to work "raw", I did find a workaround. If I put
          <properties>
          <mytimestamp>${build.timestamp}

          </mytimestamp>
          </properties>
          into the pom.xml and then use $

          {mytimestamp}

          in the .properties file, it indeed does expand to 20090701-1656.

          Show
          Matthew McCullough added a comment - Per Wendy's last comment captured from benson0 and Jason, I'm after the same thing. I have a .properties file that is part of our filtered resources that I want to put the timestamp into. If I put $ {build.timestamp} into the .properties file it isn't replaced. I see this interpolation in the source of the 2.2.0 branch of Maven, which we are using, in the file maven-project/src/main/java/org/apache/maven/project/interpolation/BuildTimestampValueSource.java Even though I couldn't get it to work "raw", I did find a workaround. If I put <properties> <mytimestamp>${build.timestamp} </mytimestamp> </properties> into the pom.xml and then use $ {mytimestamp} in the .properties file, it indeed does expand to 20090701-1656.
          Hide
          Benjamin Bentmann added a comment -

          Matthew, I believe there is probably a misunderstanding. We have to distinguish what gets interpolated (and by whom). The Maven core is only responsible for interpolating the POM, not the resources or any other project source files. The latter is the job for plugins, usually the Maven Resources Plugin. So you should fill the issue at the plugin which needs to be updated to support the timestamp as a new interpolation source. The plugin can fetch the value from the MavenSession.

          BTW, I updated the site some time ago so that the feature in now documented, see Available Variable.

          Show
          Benjamin Bentmann added a comment - Matthew, I believe there is probably a misunderstanding. We have to distinguish what gets interpolated (and by whom). The Maven core is only responsible for interpolating the POM, not the resources or any other project source files. The latter is the job for plugins, usually the Maven Resources Plugin. So you should fill the issue at the plugin which needs to be updated to support the timestamp as a new interpolation source. The plugin can fetch the value from the MavenSession . BTW, I updated the site some time ago so that the feature in now documented, see Available Variable .
          Hide
          Thomas Champagne added a comment -

          I created an issue for the Maven Resources Plugin about expanding the $

          {maven.build.timestamp}

          variable in filter resources : MRESOURCES-99

          Show
          Thomas Champagne added a comment - I created an issue for the Maven Resources Plugin about expanding the $ {maven.build.timestamp} variable in filter resources : MRESOURCES-99

            People

            • Assignee:
              John Casey
              Reporter:
              Brett Porter
            • Votes:
              7 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: