Add a copyright notice to your code.

how I did it last time - omer

For the series “How I did it last time?”, it’s better if this time I write it down to avoid to google it again.

How do I add a custom copyright notice to my android projects?

It is actually relatively simple to do that, you just need to remember which menu and which settings to modify :-).

First of all, you need to decide whether you want to apply your copyright to all your projects in android studio or only to the current opened project.

For all projects, go to: File -> Default Settings.

preferences-global

For the current project only, click the Preference icon showed below.

preferences-current-project

The rest of the steps are similar for both starting points illustrated above.

Go to Copyright Profiles from Editor -> Copyright.

preferences-current-project-2

Click on the “+” icon to create your own Copyright Profile.

new

Type your Copyright text in next window. Keep in mind that you can use in your text a few variables like:

  • $today : for the current date and time;
  • $today.year : to access the year information of the current date;
  • $username : the currently used username in android studio;
  • and others.

formatting

Once you finished your text, click on the Validate button to make sure that it complies with the “velocity” template. If it is valid, click on Apply.

validation

At this point go back to the menu item Copyright, where you can now select your newly created copyright from the drop down box. Click again on “Apply/Ok.

apply

Now your copyright is ready to be used. If you create a new file, it will be automatically generated at the top of the file.

result

In case you want to manually add it to an existing file, then right-click at the top of the file and select “Generate…” as shown below.

generate

A mini-window will open.

generate 2

Click Copyright and your text will automatically be added at the top of the file!

Obviously you don’t want to repeat this manual update to all your existing files, so I recommend to right-click on any folder of the project as shown in the following picture and to select “Update Copyright…”.

update all

At this point you can choose to add your copyright recursively to the whole project.

update all 2

That’s it!

It was easy…maybe since I have written it down I will remember how to do it again in future 🙂

Advertisements

One thought on “Add a copyright notice to your code.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s