我们经常看到成熟的开源项目在每个文件都有完整的版权声明信息,通常以Copyright (c) 开通的注释,今天就来介绍如何在Android studio/IntelliJ IDEA 中管理这些版权信息
编辑copyright
Ctrl+Alt+a打开搜索输入Copyright 打开File -> Settings -> Editor -> Copyright -> Copyright Profiles
在这里可以创建版权信息档案,每个档案都有一个名字,例如Apache 2.0或者GNU,便于以后使用。
模板中可用变量NameTypeComment$todayDateInfoThe current date and time.
$file.fileNameStringThe name of the currently opened file where the notice is to be generated.
$file.pathNameStringThe complete path and name of the currently opened file where the notice is to be generated.
$file.classNameStringThe name of the currently opened Java file where the notice is to be generated.
$file.qualifiedClassNameStringThe fully qualified name of the currently opened file where the notice is to be generated.
$file.lastModifiedDateInfoThe date and time when the current file was last changed.
$project.nameStringThe name of the current project.
$module.nameStringThe name of the current module.
$usernameStringThe name of the current user.
DateInfo 对象包含以下属性yearintThe current year.
monthintThe current month (1-12).
dayintThe current date of month (1-31).
hourintThe current hour (0-11).
hour24intThe current hour (0-23).
minuteintThe current minute of the hour (0-59).
secondintThe current second of the minute (0-59).
例如Apache 2.0Copyright $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 v3Copyright (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 .
使用copyright使用默认copyright
在File -> Settings -> Editor -> Copyright 中可以设置默认的版权信息,点击加号scope选择Project Files 可以设置当前项目默认版权信息。
在当前文件插入copyright
Ctrl+Alt+a 搜索copyright选择copyright
整个项目更新copyright
Ctrl+Alt+a 搜索copyright选择update copyright