Apache开源协议详解 2.0 协议详解
# Apache 2.0 协议详解
# 一、为什么大厂偏爱 Apache 2.0
Google、Microsoft、Apple 等大公司在开源核心项目时,几乎清一色选择 Apache 2.0。Kubernetes、Android、Spring Framework、Swift、TensorFlow 都在用它。
原因只有一个:Apache 2.0 在 MIT 的自由度之上,额外提供了专利授权和商标保护。 对大公司来说,专利风险是比代码版权更大的法律隐患。
# 二、Apache 2.0 的四大核心权利
# 2.1 版权许可(Copyright License)
与 MIT 几乎一致:允许复制、修改、分发、商用、闭源。但多了两条要求:
- 必须保留 LICENSE 和 NOTICE 文件
- 修改过的文件必须标注修改
You must cause any modified files to carry prominent notices
stating that You changed the files.
2
实践中:在修改过的文件头部加上一行:
// Modified by 杨充, 2025-06-06 - Added cache layer
# 2.2 专利许可(Patent License)—— 关键区别
这是 Apache 2.0 与 MIT 最本质的区别:
每个贡献者授予你永久、全球、非排他、免费、不可撤销的专利许可。
翻译成人话:代码里用到的专利,你可以免费使用。如果有人贡献了包含其专利技术的代码,然后反过来以此专利起诉使用者,那么该贡献者授予你的专利许可立即终止。
这是一个"防御性终止"条款,防止"我先给你代码,再告你用我的专利"这种恶意行为。
# 2.3 商标限制
本许可不授予使用贡献者商号、商标、服务标识的许可。
你不能说"本产品由 Apache 基金会认证"——除非你获得了明确授权。这也是为什么 K8s 社区对第三方"Kubernetes 认证"有专门的管理流程。
# 2.4 免责声明
与 MIT 一致:软件"按原样"提供,不承担任何保证责任。
# 三、NOTICE 文件:Apache 2.0 特有的要求
MIT 只需要 LICENSE,Apache 2.0 还需要 NOTICE:
my-project/
├── LICENSE ← Apache 2.0 协议文本
├── NOTICE ← 第三方依赖的协议声明
└── src/
2
3
4
NOTICE 应该包含什么:
My Project
Copyright 2025 杨充
This product includes software developed by
the Apache Software Foundation (http://www.apache.org/).
This product includes React (https://reactjs.org/)
Copyright (c) Meta Platforms, Inc. and affiliates.
2
3
4
5
6
7
8
什么时候需要 NOTICE?
- 你的项目本身就是 Apache 2.0 协议 → 建议创建
- 你使用了一个 Apache 2.0 库并分发了 → 必须在他的 NOTICE 要求下创建
# 四、实践操作
# 4.1 为自己的项目添加 Apache 2.0
# 自动生成
curl -o LICENSE https://www.apache.org/licenses/LICENSE-2.0.txt
# 创建 NOTICE
cat > NOTICE << 'EOF'
<项目名称>
Copyright 2025 <版权所有者>
本产品包含以下第三方软件:
(如无,可写:This product does not include any third-party components.)
EOF
2
3
4
5
6
7
8
9
10
11
// package.json
{ "license": "Apache-2.0" }
2
# 4.2 Apache 2.0 项目的结构示例
// src/main/java/com/example/App.java
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package com.example;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
上面的头部注释是 Apache 项目标准模板,普通的个人项目不需要这么严谨,但大公司项目建议保留。
# 4.3 使用 Apache 2.0 库的合规清单
| 检查项 | 说明 |
|---|---|
| ✅ 保留 LICENSE | 把原始 LICENSE 放到你的 third-party/ 目录下 |
| ✅ 保留 NOTICE | 在你的 NOTICE 文件中列出该库的版权信息 |
| ✅ 标注修改 | 如果你改了源码,在文件头部标注 |
| ❌ 不得使用对方商标 | 除非获得明确授权 |
# 五、Apache 2.0 vs MIT
| 维度 | MIT | Apache 2.0 |
|---|---|---|
| 自由度 | 极高 | 高 |
| 专利授权 | ❌ 无 | ✅ 有 |
| 修改标注 | 不要求 | 要求 |
| NOTICE 文件 | 不需要 | 需要 |
| 商标保护 | 无 | 明确禁止背书 |
| 文本长度 | ~150 词 | ~2000 词 |
| 适合谁 | 个人、小团队 | 大公司、涉及专利的项目 |
| 代表项目 | React、Vue | K8s、Android、Spring |
# 六、常见问题
Q: 我在 MIT 项目里用了一个 Apache 2.0 的库,需要加 NOTICE 吗? A: 需要。Apache 2.0 的 NOTICE 要求是向下传递的。
Q: Apache 2.0 和 GPL v2 兼容吗? A: 不兼容。 但 Apache 2.0 和 GPL v3 兼容。
Q: 我可以用 Apache 2.0 协议闭源商业发布吗? A: 可以。Apache 2.0 不要求开源衍生作品。
Q: 如果一个贡献者控告我专利侵权怎么办? A: 该贡献者授予你的专利许可自动终止,但其他贡献者的专利许可不受影响。
# 七、总结
Apache 2.0 = MIT + 专利保护 + NOTICE。如果你的项目涉及任何可能被专利化的技术,或者你是以公司名义开源的,Apache 2.0 是比 MIT 更安全的选择。
🏃 下一篇:GPL 与 LGPL 详解——当你想确保"代码永远自由"时,GPL 是唯一的武器。