English
The Complete Guide to Open Source Project License Management

In the open source community, licenses are not only a legal requirement but also a reflection of a project's professionalism. This article will show you how to use two powerful tools to establish a complete license management system for open source projects in any programming language.
Why is license management needed?
Legal compliance Clarify the project's terms of use and protect the rights and interests of authors and users.
Professionalism: Standardized project management reflects the developer's professionalism.
Community trust Clear licenses increase users' confidence in adoption.
Automated inspection: License compliance can be automatically verified in CI/CD
Introduction to Core Tools
Although these two tools are written in Go,Applicable to all programming language projects:
| tool | Function | warehouse | Supported languages |
|---|---|---|---|
| license | Generate a standalone LICENSE file. | github.com/nishanths/license | All languages |
| addlicense | Add header comments to the source code file. | github.com/google/addlicense | All languages |
Installation tools
bash
# Install license - License File Generator
go install github.com/nishanths/license@latest
# Install addlicense - Google's official header comment tool
go install github.com/google/addlicense@latestNote: Although installation requires a Go environment, the tool itself can handle source code files in any language.
License Tool User Guide
Basic usage
bash
# View Help
license -help
# View all supported license types
license -list
# Generate MIT License (output to terminal)
license mit
# Specify author name
license -name "fishfinal" mit
# Specify output file
license -o LICENSE mit
# Combined use (recommended)
license -name "fishfinal" -o LICENSE mitParameter Description
| Parameter | Abbreviation | Description | Example |
|---|---|---|---|
-name | -n | Copyright Holder Name | -name "fishfinal" |
-output | -o | Output file name | -o LICENSE |
-year | -y | Copyright year | -y 2026 |
-list | - | List all available licenses | license -list |
-update | - | Update the latest license from GitHub | license -update |
Common license examples
bash
# MIT License
license -name "fishfinal" -o LICENSE mit
# Apache 2.0 License
license -name "fishfinal" -o LICENSE apache2
# GPL 3.0 License
license -name "fishfinal" -o LICENSE gpl3
# BSD 3-Clause License
license -name "fishfinal" -o LICENSE bsd3addlicense Tool Usage Guide
Supported file types
addlicense automatically recognizes the comment styles of multiple programming languages, supporting including but not limited to:
Go (
.go)JavaScript/TypeScript (
.js,.ts,.jsx,.tsx)Python (
.py)Java (
.java)C/C++ (
.c,.cpp,.h,.hpp)Ruby (
.rb)PHP (
.php)Rust (
.rs)Shell (
.sh)and more...
Basic usage
bash
# Add MIT license headers to all code files (auto-detect language)
addlicense -c "fishfinal" -l mit .
# Add to a specific language file
addlicense -c "fishfinal" -l mit *.py
# Skip specific directories
addlicense -skip node_modules,vendor -c "fishfinal" -l mit .
# Check whether all files have a license (used in CI)
addlicense -check .Parameter Description
| parameter | Description | example |
|---|---|---|
-c | Copyright holder name | -c "fishfinal" |
-l | License Type | -l mit |
-skip | 跳过的目录(逗号分隔) | -skip vendor,dist |
-check | Check mode (does not modify files) | addlicense -check . |
-f | Use a custom template file | -f template.txt |
Examples of projects in different languages
bash
# Python project
addlicense -c "fishfinal" -l mit **/*.py
# JavaScript projects (excluding node_modules)
addlicense -skip node_modules -c "fishfinal" -l mit .
# Java project
addlicense -c "fishfinal" -l mit **/*.java
# Rust project
addlicense -c "fishfinal" -l mit **/*.rs
# mixed-language project
addlicense -c "fishfinal" -l mit .Complete workflow
1. Complete all operations in one go
Create scripts/add-license.sh:
bash
#!/bin/bash
set -e
YEAR=$(date +%Y)
AUTHOR="fishfinal"
LICENSE_TYPE="mit"
echo "📝 Generating LICENSE file..."
license -name "${AUTHOR}" -o LICENSE ${LICENSE_TYPE}
echo "📝 Adding header comments to source code..."
addlicense -c "${AUTHOR}" -l ${LICENSE_TYPE} .
echo "✅ License management completed!"2. Manual execution
bash
# Step 1: Generate the LICENSE file
license -name "fishfinal" -o LICENSE mit
# Step 2: Add header comments to all code files
addlicense -c "fishfinal" -l mit .Makefile integration
Applicable to any language project:
makefile
.PHONY: license
license:
@echo "📝 Manage project license..."
@command -v license >/dev/null 2>&1 || { \
echo "Installing license..."; \
go install github.com/nishanths/license@latest; \
}
@command -v addlicense >/dev/null 2>&1 || { \
echo "Install addlicense..."; \
go install github.com/google/addlicense@latest; \
}
license -name "fishfinal" -o LICENSE mit
addlicense -c "fishfinal" -l mit .
.PHONY: check-license
check-license:
@addlicense -check . || { \
echo "❌ Some files are missing license headers"; \
echo "Run 'make license' to fix"; \
exit 1; \
}
@echo "✅ All file licenses are complete"CI/CD integration
GitHub Actions (suitable for any language project)
at .github/workflows/license.yml Chinese:
yaml
name: License Check
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
license:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Install addlicense
run: go install github.com/google/addlicense@latest
- name: Check license headers
run: addlicense -check .GitLab CI
At .gitlab-ci.yml Chinese:
yaml
license-check:
stage: test
image: golang:1.21
script:
- go install github.com/google/addlicense@latest
- addlicense -check .
only:
- merge_requestsUse Docker (no Go environment required)
bash
# Run with Docker (suitable for CI environments)
docker run --rm -v $(pwd):/app -w /app golang:1.21 \
sh -c "go install github.com/google/addlicense@latest && addlicense -check ."Common License Selection Guide
| license | Applicable scenarios | Features |
|---|---|---|
| MIT | Most permissive, suitable for general-purpose libraries. | Commercial use is permitted, provided the copyright notice is retained. |
| Apache 2.0 | Large-scale projects, enterprise-grade | Explicit patent licensing, with a contributor agreement |
| GPL 3.0 | Emphasize degrees of freedom | Derivative works must be open source. |
| BSD 3-Clause | academic project | Similar to MIT, using the author's name for promotion is prohibited. |
不同语言项目的 .gitignore 配置
Python project
bash
addlicense -skip venv,__pycache__,*.pyc -c "fishfinal" -l mit .Node.js project
bash
addlicense -skip node_modules,dist,build -c "fishfinal" -l mit .Java project
bash
addlicense -skip target,*.class -c "fishfinal" -l mit .Rust project
bash
addlicense -skip target -c "fishfinal" -l mit .Custom license header template
Create template file license-template.txt:
Copyright (c) {{.Year}} {{.Holder}}
Licensed 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.Use custom template:
bash
addlicense -f license-template.txt -c "fishfinal" .Frequently Asked Questions
Q: Can these two tools only be used for Go projects?
A Absolutely not! They are written in Go, but can handle source code files in any programming language. addlicense automatically recognizes the comment styles of different languages.
Q: How can I check which licenses the license tool supports?
A: Run license -list View all supported license types.
Q: Does addlicense overwrite existing comments?
A: No. By default, addlicense skips files that already have license comments, making it safe and reliable.
Q: Must Go be installed to use it?
A Installation requires a Go environment, but after installation it is a standalone binary that can run in any environment. In CI, you can also use the Docker method.
Q: How to process only newly added files?
A: Use in CI addlicense -check Check, used in conjunction with Git diff.
Real project examples
Python Project (Django)
bash
# 1. Initialize project
django-admin startproject myproject
# 2. Create LICENSE
license -name "fishfinal" -o LICENSE mit
# 3. Add header comments (skip virtual environment)
addlicense -skip venv -c "fishfinal" -l mit .Node.js project (React)
bash
# 1. Initialize project
npx create-react-app myapp
# 2. Create LICENSE
license -name "fishfinal" -o LICENSE mit
# 3. Add header comments (skip node_modules and build)
addlicense -skip node_modules,build -c "fishfinal" -l mit .Rust project
bash
# 1. Initialize project
cargo new myproject
# 2. Create LICENSE
license -name "fishfinal" -o LICENSE mit
# 3. Add header comments (skip target)
addlicense -skip target -c "fishfinal" -l mit .Summary
Use license+addlicense The combination plan, you can for Any programming language Project:
Quickly generate a standard LICENSE file
Automatically add code header comments
Integrate into CI/CD for continuous checks
Maintain project professionalism and compliance.
Supports custom templates
Unified cross-language project management
Whether you’re a Python, JavaScript, Java, Rust, or any other language developer, this toolkit works perfectly!
Related resources: