I find it unnecessarily duplicated to have it in each code file, but I see it on most open source projects. Should I do that same, or just include a single license outside the code?
-
1See also http://programmers.stackexchange.com/questions/125836/do-you-have-to-include-a-license-notice-with-every-source-file – om-nom-nom Jul 27 '15 at 23:17
-
1You've got to **exclude warranty** in each source file, otherwise you might get caught out. (Note that a proper editor, like Vim, can be easily configured to fold the warranty exclusion boilerplate for you out of sight automatically.) – Evgeni Sergeev Mar 05 '16 at 10:40
10 Answers
A single one outside the code, please! I don't know about the others, but I hate seeing the same thing on top of every file.
I think I've read it a few times, just by page_down-ing through it.

- 17,587
- 13
- 87
- 117

- 60,248
- 49
- 165
- 242
-
2
-
12I disagree with Zifre. Any repeated license at the top is irritating for me. – strager May 10 '09 at 19:55
-
50It's reasonable and sensible to identify which license each source file was released under, because the file might be separated from the rest of the code (reuse - encouraged, in general, by Open Source), and if the file contains no information about the licence, it's trickier to track back to the correct licence. But the whole licence in each file - no; that would be grotesque for GPL or LGPL. As already suggested, for the short licences, it's a nuisance to have the actual licence text in the file, but it's a judgement call. But it is sensible to identify which licence it's released under. – Jonathan Leffler May 10 '09 at 20:43
-
14I just updated the file headers in my project to have only three lines: copyright, name of license, and an URL to the license text. It shorted my headers from 26 lines (BSD) to 3 lines. :) – Esko Luontola May 10 '09 at 21:00
-
@Esko Luontola - +1 - yes, I mentioned that approach somewhere in the comments also. IMHO, the best one. The user can't "accidentaly not see the licence" if you warn him with a link to it, and you're not clogging the screen with the actual licence text. – Rook May 10 '09 at 21:06
-
@Jonathan Leffler - Nice point Jonathan. Esko's approach takes care of that problem also, just include the files of all licences you're using in your code, and point to them. I prefer to see even the short licences in separate files. – Rook May 10 '09 at 21:07
-
3@Esko: Can you please post a sample? I don't know what you have written for the copyright. Thanks. – Joan Venge May 11 '09 at 16:46
-
Would it be permissible to mention the license at the top of the file and include it in a comment block at the bottom? E.g. "Distributed under the MIT License, Available at the End of this Document `\n...Code...\n` Permission is hereby granted.... WARRANTY... EOF" – fny Jan 21 '13 at 04:50
-
8This answer is marked as solution, but in my oppinion the question is still open as long we have no `evidence for the legal situation`. `Perhaps a lawyer can add a link to a court decision`. – Jonas Stein Mar 11 '13 at 01:58
-
2I had once a issue with some source code where they copyright holder told me : No no, that files is NOT on this and that license, even though the large file was added as the base. Just saying that it's a fray area where a person not holding the copyright might run into issues and get whissled back. Please add a small copyright on each file! – R. van Twisk Dec 19 '13 at 23:18
-
@ries - Just as you said; you "once had an issue"; those situations are relatively rare. Can we take this as a general guideline and deal with those rare cases on a case-by-case basis? – Rook Dec 20 '13 at 07:19
-
A small copyright can help if/when individual files (or portions of) are copied for reuse, but it should not be necessary! The person copying an individual file (or portion of) is responsible for including the LICENSE in that copy when they do it. – straya Oct 30 '16 at 07:17
-
This is so stupid, why the text of the license is not simply adjusted to apply it by default to all the files in the project / repository which has the license? It should be possible to come up with a good default. I absolutely hate having non-domain related noise in my code. – User Apr 30 '21 at 13:16
EULA is the wrong term here, as the people looking at source code usually are not end users.
Legally, it makes no difference either; copyright does not need to be declared explicitly.
Basically, all you achieve is a lower risk of people accidentally violating your license terms. You'll have to decide how important that is to you.
I'd say the best compromise is to put a very short header containing a link (absolute URL as well as relative within the project) to the full license text into each source code file. That way, anyone who cares about the license knows where to find it (ideally, people who're willing to pay massive license fees; you certainly want those people to be able to contact you!)

- 342,105
- 78
- 482
- 720
-
1
-
1@kekoav: copyleft is less restrictive than copyright. By default, you can't make derivative works. – Zifre May 10 '09 at 19:58
-
-
You mean a url, right? In that case would be complain that they didn't have internet, so didn't know the license? – Joan Venge May 10 '09 at 20:10
-
3In a dispute, that would not be a valid argument. If told that there is a license, and how to retrieve it, you can't site technical barriers that are your fault that prevented you from seeing the license. – Lasse V. Karlsen May 10 '09 at 20:16
-
1"Copyleft" is slang for the the basic idea of GPL to "subvert" copyright restrictions from within, i.e. using your rights as a copyright holder to grant a license to anyone to use your code freely, but force them to release THEIR code which is based on yours under the same license. – Michael Borgwardt May 10 '09 at 20:47
-
Yes, but a "copyleft" work is still copyrighted. Without copyright laws, the copyleft license does not work. – jmucchiello May 10 '09 at 21:28
-
2Correct; but in this context, as Zifre said, it does not matter. If you don't know the license under which a particular piece of code was published, you have to assume you're not allowed to use it at all. So as the publisher, you don't have to go to extra lengths to make people read the license. – Michael Borgwardt May 10 '09 at 21:59
It might depend on the license. The GPL distinguishes between preamble
and license
. It clearly states, that the (annoying) preamble must be part of the code:
Can I omit the preamble of the GPL, or the instructions for how to use it on your own programs, to save space?
The preamble and instructions are integral parts of the GNU GPL and may not be omitted. In fact, the GPL is copyrighted, and its license permits only verbatim copying of the entire GPL. (You can use the legal terms to make another license but it won't be the GNU GPL.) (1)
Source: 1) http://www.gnu.org/licenses/gpl-faq.html#GPLOmitPreamble
See also http://softwarefreedom.org/resources/2012/ManagingCopyrightInformation.html
A free ebook from ifrOSS explains and comments the GPL 2 in german language. There is another one for GPL 3
For a well founded answer you should ask for a legal advice which is not available on sx. If you can not find a lawyer for your (open source) project, have a look at the FSFE legal network.

- 6,826
- 7
- 40
- 72
-
10Preamble and instructions *are* part of the *full* license, but nothing says you have to put the *full* license in *every* file. `[...] attach the following notices to the program.` - *following notices* is only a small section of the full license. `safest to attach them to the start of each source file` - *safest* but *not* required. `each file should have at least the "copyright" line and a pointer to where the full notice is found.` - only requirement is the copyright line with a pointer to the rest. It's fine to put the *full* license in one separate file. – toxalot Mar 12 '14 at 04:02
-
4
-
You are wrong. You are neither forced to add the full license to the code (not that anyone would), but you are also [NOT](https://www.gnu.org/licenses/gpl-faq.html#LicenseCopyOnly) forced to add any note in your code at all (the famous GPL header in files) - though it might make sense. What you quote simply says is, that you cannot rip the GPL text apart. – user136036 Oct 15 '20 at 17:06
No, you don't have to put the license in each source code file.
If you look closer, most FOSS applications don't do that either. They put a copyright statement at the top of each file and a short sentence telling you what license the file is under and where you can find the full text of the license. They usually point you to the COPYING or LICENSE file containing the full text of the license and/or to a website that contains the full text (in case the COPYING file isn't there anymore).
Like Michael Borgwardt said in his answers, legally you don't have to do this. But it is advisable for source code that you intend to distribute since people can immediately see who has the copyright and what the license is.

- 22,978
- 13
- 65
- 96
-
1This. The copyright notice should include a reference to the name of license (if it is a standard one) and a description of how to find the license file in the source tree. – jmucchiello May 10 '09 at 21:27
I think the reasoning behind putting it in each file is a legal one. If the agreement is in each file, there is no chance of someone stumbling across a piece of code without being exposed to the license.
It may not be a good one, but all the big boys use it so if it's just visual pain, I would look for a better reason not to do the same.
If you're using GPL this is more of an issue, but if you're using public domain licenses like BSD or MIT, I don't think you really care what people do with the code anyway. I suppose it depends on how strict your license is.

- 27,892
- 14
- 72
- 91
-
1Well, in that case, just point in each file that upon continuing with it, you agree to the licence in file licence.txt. But don't copy/paste the same text in each file. I sometimes find files with code shorter then the licence. – Rook May 10 '09 at 20:32
-
Yeah, I agree that it works just as well that way, especially for long licenses. Even though it may not be legally essential, or even supportable in court, a reference to your license is at the very least good to inform people without them having to go search around for what license the code is under. – Kekoa May 11 '09 at 15:41
IANAL,
Assuming you are talking about licensing, not a EULA, you can put the license outside. This is almost always done with really long licenses such as the GPL. It would be silly to put the entire GPL license in every file. Usually you would just have some type of notice saying where you can find the actual license. This is perfectly legal. However, with really short licenses such as BSD/Apache/MIT/whatever, it is simpler to just include to license in every file, since the notice saying where to find the license would be almost as long as the license itself.

- 26,504
- 11
- 85
- 105
If your code is going to be compiled so you are just distributing a binary then it really does not matter. Because when you create a binary, the comments are removed before the compilation process takes place. It only matters if you will be distributing the actual source code either open source or closed source. This typical matters if you will be distributing a application in a scripting language that doesn't compile.

- 1,296
- 9
- 13
-
-
You can create a hard-coded string to contain the license, so it'll appear on the binary, but that's probably too much :). – Liran Orevi May 10 '09 at 21:12
-
I'm over a decade late on commenting here, but this was the most fitting answer that applied to my situation. I'm getting involved in development work in a new community where I noticed everyone was including their license at the top of every script. But it makes sense now that those scripts are being copied and distributed among end users who just run the scripts have no idea what they do when they run them. After that script passes hands enough times, an external license file would have got long forgotten about. – Ryan Hart May 28 '22 at 04:19
It depends on what the license dictates. The GPL, for example, instructs you to put a short notice in every source file, include the entire license somewhere in your source distribution, and make your source distribution available to anyone who get a copy of the binary distribution.
If you disagree with this, and it is YOUR code, you're free to choose a more agreeable license, or create your own.

- 402
- 2
- 5
What I do is to put a two-line comment at the top of the file, stating my company's name, last revision date and the name of the license the source file has, then at the very bottom of the file a short version of the license.
Of course, the full license (all of them in case of multiple licenses) is always enclosed on source file and release directories.

- 1,860
- 4
- 25
- 44
You dont need it for the license, a single external file will do as long as its clear what files it covers.
However for Copyright you should have the copyright notice on every piece of text.

- 27,109
- 7
- 50
- 78
-
-
INAL but a license is a contract between you and the user/customer. Copyright is an assertion of ownership of a piece of a written work. Someone could pick up a fragment of your code and reasonably claim it wasn't copyright because the notice was missing. Dont worry though "Copyright Joe Soap (Cleansoft Inc.)" is all you need. – James Anderson May 12 '09 at 01:33
-
14You're so wrong about that. While it's generally good to indeed add copyright notices everywhere just to be clear, but that doesn't make it fair game to "assume it wasn't copyrighted" Because you know EVERYTHING is copyrighted. When someone obtains source code, he may find a license statement that allows him to use it, or he may find out that it is in the public domain for one reason or another. If he doesn't though it is copyrighted and can't be copied. Copyright is an automatic thing and it's good to mention it, but not doing so doesn't mean you lose it... – Jasper Jun 03 '10 at 13:37
-
So true! Copyright is so automatic, in fact, that many people fail to realize that there are circumstances where they cannot copyright what they think is their own code (i.e. for instance, when using an example of code provided by an author of the language on their copyrighted website.) Chances are, that Microsoft will not lay claim to code you based entirely on their examples and tutorials, when you write software in Typescript; but if its clear that your code is comprised in a way where every code flow can be found on their site (in examples) - they certainly could! – Rik Sep 10 '22 at 07:21