Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate random number during Maven build

Tags:

java

random

maven

Is there a plugin (or another easy way) to generate a "random" number as part of a Maven build? I would like to assign this number to a property that I can then use in the pom.xml file for some other purposes, e.g. for a filter value.

The number doesn't have to be completely random (hence the quotes), something using the current timestamp as a seed would be perfectly OK.

like image 934
nwinkler Avatar asked Mar 27 '13 09:03

nwinkler


2 Answers

The default installation of maven offers a variable named maven.build.timestamp, which gives you a timestamp. You can control the format with

  <properties>
    <maven.build.timestamp.format>yyyyMMdd-HHmm</maven.build.timestamp.format>
  </properties>

which follows the SimpleDateFormat rules. So, you can simply just use ${maven.build.timestamp} to get a formatted timestamp :)

http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Available_Variables

like image 186
JustDanyul Avatar answered Sep 20 '22 13:09

JustDanyul


You can use the timestamp maven plugin : http://code.google.com/p/maven-timestamp-plugin/

It generates the timestamp in maven property in the format you like.

like image 22
benzonico Avatar answered Sep 20 '22 13:09

benzonico