在每个代码文件中放入许可证?

我发现在每个代码文件中都有它不必要的重复,但是我在大多数开源项目中都看到它。我是应该这样做,还是只在代码之外包含一个许可证?

35588 次浏览

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.

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.

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.

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!)

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.

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.

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.

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.

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.

It might depend on the license. The GPL distinguishes between ABC0 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.