Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add time-stamp information to Maven artifacts?

I am upgrading a large build-system to use Maven2 instead of Ant, and we have two related requirements that I'm stuck on:

  1. We need to generate a time-stamped artifact, so a part of the package phase (or wherever), instead of building

    project-1.0-SNAPSHOT.jar 

    we should be building

    project-1.0-20090803125803.jar 

    (where the 20090803125803 is just a YYYYMMDDHHMMSS time-stamp of when the jar is built).

    The only real requirement is that the time-stamp be a part of the generated file's filename.

  2. The same time-stamp has to be included within a version.properties file inside the generated jar.

This information is included in the generated pom.properties when you run, e.g., mvn package but is commented out:

#Generated by Maven #Mon Aug 03 12:57:17 PDT 2009 

Any ideas on where to start would be helpful! Thanks!

like image 588
Ryan Avatar asked Aug 03 '09 20:08

Ryan


People also ask

Which file maintains all the artifacts information in Maven?

An artifact is apparently a directory satisfying some constraints, e.g. it must contain a file called maven-metadata. xml and a file called <artifactId>-<version>. pom .

What is plugin tag in Maven?

Plugins are the central feature of Maven that allow for the reuse of common build logic across multiple projects. They do this by executing an "action" (i.e. creating a WAR file or compiling unit tests) in the context of a project's description - the Project Object Model (POM).


1 Answers

Maven versions 2.1.0-M1 or newer have built in special variable maven.build.timestamp.

<build>   <finalName>${project.artifactId}-${project.version}-${maven.build.timestamp}</finalName> </build> 

See Maven documentation for more details.


For older Maven versions a look at maven-timestamp-plugin or buildnumber-maven-plugin.

If you use maven-timestamp-plugin, you can use something like this to manipulate resulting artifact name.

<build>    <finalName>${project.artifactId}-${project.version}-${timestamp}</finalName> </build> 

And this configuration for buildnumber-maven-plugin should create a ${timestamp} property which contains the timestamp value. There doesn't seem to be a way to create the version.properties file directly with this plugin.

<configuration>    <format>{0,date,yyyyMMddHHmmss}</format>    <items>       <item>timestamp</item>    </items>  </configuration> 

These three sites are also worth checking out.

like image 108
Juha Syrjälä Avatar answered Sep 23 '22 11:09

Juha Syrjälä