如何将当前年份插入IntelliJ IDEA版权模板?

时间:2015-06-03 10:58:03

标签: intellij-idea velocity

我试图在IntelliJ IDEA版权设置中为MIT许可证制作Apache Velocity模板。我希望它打印年份的2015-${current_year}。以下是我尝试放入设置→版权→版权配置文件→MIT→版权文本

#set ($current_year = $dateTool.getCurrentDate('yyyy'))
Copyright (c)  2015-${current_year}, My Name

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

但是,当我使用此模板在源文件中生成许可证标题时,它不打印当前年份编号,它只打印纯文本${current_year}

如何让它打印当年?

3 个答案:

答案 0 :(得分:23)

This page of the documentation解释设置→版权→版权配置文件的内置Velocity变量:

Name    Type        Comment
$today  DateInfo    The current date and time.
...
DateInfo has the following properties:
year    int         The current year.

所以在我的情况下,我在模板中需要这个:

Copyright (c)  2015-${today.year}, My Name

答案 1 :(得分:1)

正如here所述,${YEAR}是要走的路

答案 2 :(得分:0)

#set($year = $today.year + 1900)

,可以称为${year}