1. 前言
在日常的开发工作中,我们经常会需要用到一些优秀的开源框架,如Spring Framework。在使用开源框架的过程中,有时候会需要查看它的源代码,我们会发现,在Spring源文件的开头都会有一段关于LICENSE的声明:
添加LICENSE文件头信息的方式大致可以分为两种:
- 手动复制
- IDE自动生成
手动复制就不说了,接下来说一下如何在IDEA中配置自动生成LICENSE信息。
2. 设置LICENSE模板
打开 File> Settings设置面板。
选择Editor>Copyright > Copyright Profiles, 然后添加一个新的profile配置,起名为 tinyking@apache , 并将LICENSE信息复制到模板配置中:
信息如下:
Copyright 2019-$today.year Jianchao Wang(akingchao@qq.com)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.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.
3. 启用配置
选择上一级的Copyright,选中刚才添加的Profile,Scope选择All,这样就会在当前项目中启用该配置。
启动配置后,再新建Class文件时,IDEA就会自动在文件顶部添加LICENSE信息。
4. 总结
工具可以很好的帮我们完成很多工作,尤其像这样简单的,机械的劳动,我们就交给工具好了,这样省下的时间还可以做更有意义的事情。