It is a pain to manually update copyright messages in open source code that you’re going to release on GitHub 😩. There is a better way. You can have JetBrains based IDEs (Android Studio, Webstorm, etc) just do it for you.
I’m going to use Android Studio as an example, but this works on Webstorm, etc.
How to add copyright to Android Studio
Open Android Studio and follow these setps in order to automagically generate copyright messages for all your project files.
Step 1 – Create a copyright profile
- Open Preferences, and navigate to
- Create a new profile and name it
- Paste the following text into the dialog box, replacing the default text that’s already there.
Copyright $today.year YOURCOMPANY. All rights reserved. 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.
- Make sure to replace YOURCOMPANY with your name or the name of the company that the copyright belongs to.
$today.yearsnippet is a Velocity template string that just inserts the current year into the copyright message when it’s updated.
- Click on OK.
Step 2 – Create a scope to apply the
android profile to
- In Preferences, navigate to
- Apply the
androidprofile the default for the project.
- Add the
Project Filesscope and apply
- Click on OK.
Step 3 – Tell Studio to apply this to all the files
- Right click on your project’s root and select
Update Copyright ....
- Make sure to apply this to the
Update existing copyrights.
- Click OK.
Step 4 – Quick way to update copyright for commits
- When you commit your changes using Android Studio, you can just check the
Update Copyrightso that the changed files will have their copyright messages updated.