Generate Timestamp Maven

By default maven is not configure to create unique build number when you package you project. This is required if you are using continuous build tools to generate project archive. By default maven generate the artifact using you project artifactId and version. So if you project has below:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.javahonk</groupId>
	<artifactId>GenerateBuildNumber</artifactId>
	<version>0.0.1-SNAPSHOT-${timestamp}</version>

</project>
  • It will generate artifact as below when you package or intall your project:

Generate Timestamp Maven

  • Each time if you take build it will generate the same version. To change this behavior and if you want to include unique version every time you could include time-stamp in it so please modify your pom.xml, include below properties:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.javahonk</groupId>
	<artifactId>GenerateBuildNumber</artifactId>
	<version>0.0.1-SNAPSHOT-${timestamp}</version>

	<properties>
		<timestamp>${maven.build.timestamp}</timestamp>
		<maven.build.timestamp.format>yyyyMMdd-HHmmssSSS</maven.build.timestamp.format>
	</properties>

</project>
  • Now after adding this every time when you take build it will generate unique artifact which include time-stamp as below:

2015-10-26 23_19_22-Java EE - GenerateBuildNumber_pom.xml - Eclipse

 

  • For more information please read maven documentation here

Leave a Reply

Your email address will not be published. Required fields are marked *