如何访问maven.build.timestamp进行资源过滤 [英] How to access maven.build.timestamp for resource filtering
问题描述
我正在使用maven 3.0.4,并希望使构建时间戳可供我的应用程序访问.为此,我将占位符放在.properties
文件中,并让Maven在构建时进行过滤.尽管这对于${project.version}
正常工作,但${maven.build.timestamp}
不能在过滤时替换.
I am using maven 3.0.4 and would like to make the build timestamp accessible to my application. For this, I'm putting a placeholder in a .properties
file and let maven filter on build. While this is working fine for ${project.version}
, ${maven.build.timestamp}
is not substituted on filtering.
该属性似乎可以在构建中使用-我可以使用它来修改工件名称:
The property seems to be available on build - I can use it to modify the artifact name:
<finalName>${project.artifactId}-${maven.build.timestamp}</finalName>
那么为什么它不能用于资源过滤?而且,更重要的是,如何使它可访问?
So why is it not available for resource filtering? And, more importantly, how do I make it accessible?
推荐答案
我发现了这篇文章,说明由于 Maven中的错误,构建时间戳记不会传播到过滤器中.解决方法是将时间戳包装在另一个属性中:
I have discovered this article, explaining that due to a bug in maven, the build timestamp does not get propagated to the filtering. The workaround is to wrap the timestamp in another property:
<properties>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
</properties>
然后可以按预期进行过滤
Filtering then works as expected for
buildTimestamp=${timestamp}
这篇关于如何访问maven.build.timestamp进行资源过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!