I am upgrading a large build-system to use Maven2 instead of Ant, and we have two related requirements that I'm stuck on:
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.
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!
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 .
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With