本年度的Maven物业 [英] Maven property for current year
问题描述
我有一个Maven项目,该项目在构建过程中会生成属性文件.我想添加的属性之一是该项目的版权日期.
I have a maven project that generates a properties file during a build. One of the properties I would like to include is the copyright dates for the project.
我具有这样定义的属性:
I have the property defined as such:
<properties>
<copyright-years>${project.inceptionDate}-2016</copyright-years>
</properties>
我在其他地方使用build.timestamp
属性.
I'm using the build.timestamp
property elsewhere.
我如何才能用当前年份替换属性中的2016年,理想情况下,只更改一次实例中的时间戳格式?
How can I replace the 2016 in the property with the current year, ideally by changing the timestamp format in just this one instance?
推荐答案
您可以使用 build-helper-maven-plugin
即可完成此任务.它有一个 timestamp-property
目标,用于将具有给定格式的时间戳存储到Maven属性中:
You can use the build-helper-maven-plugin
for this task. It has a timestamp-property
goal that can be used to store a timestamp with a given format into a Maven property:
根据当前日期和时间设置属性.
Sets a property based on the current date and time.
优点是它不会强制您定义特定的maven.build.timestamp.format
,如果您打算在其他地方以另一种方式格式化当前日期,这将不方便.配置示例如下:
The advantage is that it doesn't force you to define a specific maven.build.timestamp.format
, which would not be convenient if you intend to format the current date in a second way elsewhere. A sample configuration would be:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>timestamp-property</id>
<goals>
<goal>timestamp-property</goal>
</goals>
<phase>validate</phase>
<configuration>
<name>current.year</name>
<pattern>yyyy</pattern>
</configuration>
</execution>
</executions>
</plugin>
这会将当前年份存储在current.year
Maven属性中.这是在执行的第一个阶段validate
阶段完成的,因此其余的构建版本都可以在${current.year}
上使用它.
This will store the current year in the current.year
Maven property. This is done at the validate
phase, which is the first phase executed, so that all of the rest of the build can use it with ${current.year}
.
这篇关于本年度的Maven物业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!