29

I'm about to push my first project to GitHub (a mini toy lisp interpreter written in C).

I've noticed that the vast majority of open source projects include their license in every source file (at the top). Is that a necessity for open source?

6
  • 1
    possible duplicate of Is a license header in source-files required?
    – gnat
    Apr 28, 2016 at 14:17
  • 5
    The question that @gnat linked to addresses the Apache license. What license are you applying? For the Apache license, as mentioned in that question, the answer is "you should". For a different license, the answer may be "you must".
    – Thomas Owens
    Apr 28, 2016 at 14:23
  • 2
    The advantage of doing so is that even if someone uses just one file from your library, they still include the licence, unless they make the effort to remove it. If the licence is in a separate file, they must make the effort to include the licence. The disadvantage is that every file now has an ugly lump of crap at the top that one must scroll past to get to the code. Your choice...
    – David Arno
    Apr 28, 2016 at 17:02
  • 7
    Possible duplicate of Do you have to include a license notice with every source file?
    – MSalters
    May 2, 2016 at 14:58

2 Answers 2

17

This is an old question, but for anyone else looking for the answer, most licenses don't require the license to be included inside each source file, as long as the license is included with the source code. Often this is done by use of a LICENSE.md or LICENSE.txt file included in the same repo, folder, or directory as the code.

Below is a rundown of some common open source licenses and their requirements regarding inclusion in source files.


Apache License Version 2.0

One of the (many) reasons Apache released v2.0 of the Apache License was:

... to allow the license to be included by reference instead of listed in every file... (source)

The license's Appendix seems to specify that a license notice needs to be included in the file itself, but GitHub's ChooseALicense.com says that this requirement is more of a recommendation.


MIT License

The MIT License only requires that the license text:

be included in all copies or substantial portions of the Software.


GPL / LGPL / AGPL

For the GPL, LGPL, or AGPL license, the Free Software Foundation, which runs GNU.org, does want a notice included within each file (as well as in an accompanying COPYING file containing the full license text, or COPYING LESSER if using the LGPL).

Here's how they say to include the license in your source files:

This involves adding two elements to each source file of your program: a copyright notice (such as “Copyright 1999 Terry Jones”), and a statement of copying permission, saying that the program is distributed under the terms of the GNU General Public License (or the Lesser GPL, or the Affero GPL).


Note that I am not a lawyer and this answer does not even remotely constitute any sort of legal advice.

1
  • The Appendix from Apache license exactly recommends what you said in your second clause: Attach the template to your source code, like what "ChooseALicense.com" says.
    – xuhdev
    May 29, 2019 at 23:00
8

It is not necessary (depending on the exact license though) but a good practice for both commercial and open source software. Moreover, with the emergence of a proper standard called SPDX (Software Package Data Exchange®), it becomes easier for both developers and lawyers to audit the code for copyrights and licenses.

And example of such header for C/C++ language would look like:

//  SPDX-FileCopyrightText: 2019 Jane Doe <[email protected]>
//  SPDX-License-Identifier: GPL-3.0-or-later

Moreover, there is an initiative called REUSE Software that provides good guidelines for any kind of project on how to add, manage, and audit copyright and license information. One of the results of this initiative is the automated Python tool to check the compliance for the latest REUSE and SPDX recommendations. It is called reuse and provides a linter feature, see more at their documentation page. To learn more about compliance and steps required, see the full REUSE tutorial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.