我们经常看到成熟的开源项目在每个文件都有完整的版权声明信息,通常以Copyright (c) 开通的注释,今天就来介绍如何在Android studio/IntelliJ IDEA 中管理这些版权信息
编辑copyright
Ctrl+Alt+a
打开搜索输入Copyright 打开File -> Settings -> Editor -> Copyright -> Copyright Profiles
在这里可以创建版权信息档案,每个档案都有一个名字,例如Apache 2.0或者GNU,便于以后使用。
模板中可用变量
Name | Type | Comment |
---|---|---|
$today | DateInfo | The current date and time. |
$file.fileName | String | The name of the currently opened file where the notice is to be generated. |
$file.pathName | String | The complete path and name of the currently opened file where the notice is to be generated. |
$file.className | String | The name of the currently opened Java file where the notice is to be generated. |
$file.qualifiedClassName | String | The fully qualified name of the currently opened file where the notice is to be generated. |
$file.lastModified | DateInfo | The date and time when the current file was last changed. |
$project.name | String | The name of the current project. |
$module.name | String | The name of the current module. |
$username | String | The name of the current user. |
DateInfo 对象包含以下属性
year | int | The current year. |
month | int | The current month (1-12). |
day | int | The current date of month (1-31). |
hour | int | The current hour (0-11). |
hour24 | int | The current hour (0-23). |
minute | int | The current minute of the hour (0-59). |
second | int | The current second of the minute (0-59). |
例如Apache 2.0
Copyright $today.year xxxx
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
GNU gpl v3
Copyright (C) $today.year xxxxx
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
使用copyright
-
使用默认copyright
在File -> Settings -> Editor -> Copyright 中可以设置默认的版权信息,点击加号scope选择Project Files 可以设置当前项目默认版权信息。 -
在当前文件插入copyright
Ctrl+Alt+a
搜索copyright
选择copyright
-
整个项目更新copyright
Ctrl+Alt+a
搜索copyright
选择update copyright
网友评论