如何向 Maven 工件添加时间戳信息? [英] How do I add time-stamp information to Maven artifacts?
问题描述
我正在升级一个大型构建系统以使用 Maven2 而不是 Ant,我们有两个相关的要求,我坚持:
我们需要生成一个带时间戳的工件,所以是包的一部分阶段(或任何地方),而不是构建
project-1.0-SNAPSHOT.jar
我们应该建设
project-1.0-20090803125803.jar
(其中
20090803125803
只是 jar 的YYYYMMDDHHMMSS
时间戳建).唯一真正的要求是时间戳是生成文件的文件名.
相同的时间戳必须包含在 version.properties 文件中在生成的 jar 中.
此信息包含在您运行时生成的 pom.properties 中,例如,mvn package
但被注释掉了:
#由Maven生成#Mon August 03 12:57:17 PDT 2009
任何关于从哪里开始的想法都会有所帮助!谢谢!
Maven 2.1.0-M1 或更新版本已经内置了特殊变量 maven.build.timestamp
.
<finalName>${project.artifactId}-${project.version}-${maven.build.timestamp}</finalName></build>
有关详细信息,请参阅 Maven 文档.
<小时>对于较旧的 Maven 版本,请查看 maven-timestamp-plugin 或buildnumber-maven-plugin.
如果您使用 maven-timestamp-plugin,您可以使用类似这样的东西来操作生成的工件名称.
<finalName>${project.artifactId}-${project.version}-${timestamp}</finalName></build>
这个 buildnumber-maven-plugin 的配置应该创建一个包含时间戳值的 ${timestamp} 属性.似乎没有办法直接使用此插件创建 version.properties 文件.
<预><代码><配置><format>{0,date,yyyyMMddHHmmss}</format><物品><item>时间戳</item></物品></配置>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 aYYYYMMDDHHMMSS
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!
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.
这篇关于如何向 Maven 工件添加时间戳信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!