你怎么插入当前每年投入IntelliJ IDEA的版权模板?

问题描述 投票:10回答:3

我试图让在IntelliJ IDEA的著作权设置MIT许可证Apache的Velocity模板。我想它打印2015-${current_year}在2015年。这是我一直试图把在设置→版权所有→版权所有型材→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}

我如何让它打印当前的一年?

intellij-idea velocity
3个回答
23
投票

This page of the documentation解释了设置→版权所有→版权所有型材内置速度变量:

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
投票

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


0
投票
#set($year = $today.year + 1900)

并且可以被称为如${year}

© www.soinside.com 2019 - 2024. All rights reserved.