11# CLI Licence checker for composer dependencies
22This library offers a simple CLI tool to show the licenses used by composer dependencies in your project.
3- These licenses can be verified against a list of allowed licenses to offer a way for your continuous integration
3+ These licenses can be verified against a list of allowed (or denied) licenses to offer a way for your continuous integration
44pipeline to block merging when a non-verified license is being introduced to the codebase.
55
6+ ## Upgrading from 2.x
7+
8+ Version 3.x introduces a new structured configuration format. Run the migration command to upgrade:
9+
10+ ```
11+ vendor/bin/license-checker migrate-config --remove-old
12+ ```
13+
14+ This converts your ` .allowed-licenses ` file to the new ` .license-checker.yml ` format. See [ full migration details] ( #migrating-from-2x ) below.
15+
616## Installation
717Installing should be a breeze thanks to ` composer ` :
8- Note that you need PHP 8.3 to install the latest version (2.x).
9- If you are using an older version of PHP, older versions can be installed.
18+ Note that you need PHP 8.4 to install the latest version (3.x).
1019
1120```
1221composer require madewithlove/license-checker
1322```
1423
1524## Configuration
16- To configure a list of allowed licenses, simply create an ` .allowed-licenses ` file in the root of your project (where ` composer.json ` is located).
17- The file could look like this:
25+ Create a ` .license-checker.yml ` file in the root of your project (where ` composer.json ` is located).
26+
27+ ### Allowlist mode
28+ Only the listed licenses are permitted. Any dependency using a license not on this list will be flagged:
29+ ``` yaml
30+ # .license-checker.yml
31+ allowed :
32+ - MIT
33+ - BSD-3-Clause
34+ - Apache-2.0
1835` ` `
19- # contents of .allowed-licenses
20- - MIT
21- - BSD-3-Clause
22- - New BSD License
36+
37+ ### Denylist mode
38+ All licenses are permitted **except** the ones listed. Use this when you want to block specific licenses:
39+ ` ` ` yaml
40+ # .license-checker.yml
41+ denied :
42+ - GPL-3.0
43+ - AGPL-3.0
2344` ` `
2445
46+ > **Note:** ` allowed` and `denied` are mutually exclusive — you must use one or the other, not both.
47+
2548It's possible to use a custom configuration file by passing the `--filename` (or `-f`) option to the CLI commands.
2649
2750# # Usage
28- These are the different CLI commands
51+ These are the different CLI commands :
52+
53+ # ## Check licenses
54+ ```
55+ vendor/bin/license-checker check
56+ ```
2957
3058### List used licenses
3159```
3260vendor/bin/license-checker used
3361```
3462
35- ### List allowed licenses
63+ ### List configured licenses
64+ Shows the configured allowed or denied licenses:
3665```
37- vendor/bin/license-checker allowed
66+ vendor/bin/license-checker list-config
3867```
3968
40- ### Check licenses
69+ ### Count used licenses
4170```
42- vendor/bin/license-checker check
71+ vendor/bin/license-checker count
4372```
4473
4574### Automatically generate configuration
46- This command will automatically generate an ` .allowed-licenses ` configuration based on the currently used licenses.
75+ This command will automatically generate a `.license-checker.yml ` configuration in allowlist mode based on the currently used licenses:
4776```
4877vendor/bin/license-checker generate-config
4978```
@@ -52,23 +81,28 @@ vendor/bin/license-checker generate-config
5281Passing the `--no-dev` option to the CLI commands will scope all checks to production dependencies only.
5382Checking production and development dependencies against separate configuration files is possible by passing options:
5483```
55- vendor/bin/license-checker check --no-dev --filename .allowed-licenses -production
56- vendor/bin/license-checker check --filename .allowed-licenses -including-dev
84+ vendor/bin/license-checker check --no-dev --filename .license-checker -production.yml
85+ vendor/bin/license-checker check --filename .license-checker -including-dev.yml
5786```
5887
5988### Output Formats (--format option)
60- You can now choose how license information is displayed either as a human-readable table (text) or in machine-readable JSON format.
89+ You can choose how license information is displayed — either as a human-readable table (text) or in machine-readable JSON format.
6190
6291```
6392vendor/bin/license-checker check --format=json
6493```
6594
6695```json
6796{
68- "laravel/framework" : " MIT" ,
69- "phpunit/phpunit" : " BSD-3-Clause"
97+ "laravel/framework": {
98+ "license": "MIT",
99+ "is_allowed": true
100+ },
101+ "phpunit/phpunit": {
102+ "license": "BSD-3-Clause",
103+ "is_allowed": false
104+ }
70105}
71-
72106```
73107
74108```
@@ -78,8 +112,49 @@ vendor/bin/license-checker check --format=text
78112```
79113✓ phpunit/phpunit [BSD-3-Clause]
80114✓ symfony/console [MIT]
81- ✓ vimeo/psalm [MIT]
82115```
83116
84117By default, results are printed as human-readable text.
85- Use --format=json for structured machine-readable output.
118+ Use ` --format=json ` for structured machine-readable output.
119+
120+ ## Migrating from 2.x
121+
122+ Version 3.x introduces a new structured configuration format. Here's what changed:
123+
124+ ### Configuration file format
125+ The old format was a plain YAML list in ` .allowed-licenses ` :
126+ ``` yaml
127+ # OLD format (.allowed-licenses) — no longer supported
128+ - MIT
129+ - BSD-3-Clause
130+ ` ` `
131+
132+ The new format uses a structured YAML file (` .license-checker.yml`) with an explicit `allowed` or `denied` key:
133+ ` ` ` yaml
134+ # NEW format (.license-checker.yml)
135+ allowed:
136+ - MIT
137+ - BSD-3-Clause
138+ ` ` `
139+
140+ # ## Automatic migration
141+ Use the `migrate-config` command to convert your old configuration :
142+ ` ` `
143+ vendor/bin/license-checker migrate-config
144+ ` ` `
145+
146+ This reads `.allowed-licenses` and writes `.license-checker.yml` with the `allowed:` key.
147+
148+ To also remove the old file :
149+ ` ` `
150+ vendor/bin/license-checker migrate-config --remove-old
151+ ` ` `
152+
153+ # ## Renamed commands
154+ | 2.x | 3.x |
155+ |-----|-----|
156+ | `allowed` | `list-config` |
157+
158+ # ## Other breaking changes
159+ - Minimum PHP version is now 8.4 (was 8.3)
160+ - Minimum Symfony version is now 7.4 (was 4.0)
0 commit comments