|
| 1 | +# License Resolution and Compliance |
| 2 | + |
| 3 | +This document describes the license analysis features that help you understand your project’s license and check compatibility with your dependencies. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +License analysis is **enabled by default** and provides: |
| 8 | + |
| 9 | +1. **Project license detection** from your manifest file (e.g., `package.json`, `pom.xml`) and LICENSE files |
| 10 | +2. **Dependency license information** from the Trustify DA backend |
| 11 | +3. **Compatibility checking** to identify potential license conflicts |
| 12 | +4. **Mismatch detection** when your manifest and LICENSE file declare different licenses |
| 13 | + |
| 14 | +## How It Works |
| 15 | + |
| 16 | +### Project License Detection |
| 17 | + |
| 18 | +The client looks for your project’s license with **automatic fallback**: |
| 19 | + |
| 20 | +1. **Primary: Manifest file** — Reads the license field from: |
| 21 | + - `package.json`: `license` field |
| 22 | + - `pom.xml`: `<licenses><license><name>` element |
| 23 | + - `Cargo.toml`: `license` field under `[package]` or `[workspace.package]` |
| 24 | + - `build.gradle` / `build.gradle.kts`: No standard license field (falls back to LICENSE file) |
| 25 | + - `go.mod`: No standard license field (falls back to LICENSE file) |
| 26 | + - `requirements.txt`: No standard license field (falls back to LICENSE file) |
| 27 | + |
| 28 | +2. **Fallback: LICENSE file** — If no license is found in the manifest, searches for `LICENSE`, `LICENSE.md`, or `LICENSE.txt` in the same directory as your manifest |
| 29 | + |
| 30 | +**How the fallback works:** |
| 31 | +- **Ecosystems with manifest license support** (Maven, JavaScript, Rust Cargo): Uses manifest license if present, otherwise falls back to LICENSE file |
| 32 | +- **Ecosystems without manifest license support** (Gradle, Go, Python): Automatically reads from LICENSE file |
| 33 | +- **SPDX detection**: Common licenses (Apache-2.0, MIT, GPL-2.0/3.0, LGPL-2.1/3.0, AGPL-3.0, BSD-2-Clause/3-Clause) are automatically detected from LICENSE file content |
| 34 | + |
| 35 | +The backend’s license identification API is used for accurate LICENSE file detection when available. |
| 36 | + |
| 37 | +### Compatibility Checking |
| 38 | + |
| 39 | +The client checks if dependency licenses are compatible with your project license. For example: |
| 40 | +- Permissive project (MIT) + permissive dependencies → ✅ Compatible |
| 41 | +- Permissive project (MIT) + strong copyleft dependency (GPL) → ⚠️ Potentially incompatible |
| 42 | + |
| 43 | +Compatibility results are included in the analysis report’s `licenseSummary`. |
| 44 | + |
| 45 | +## Configuration |
| 46 | + |
| 47 | +### Disable License Checking |
| 48 | + |
| 49 | +License analysis runs automatically during **component analysis only** (not stack analysis). To disable it: |
| 50 | + |
| 51 | +**Environment variable:** |
| 52 | +```bash |
| 53 | +export TRUSTIFY_DA_LICENSE_CHECK=false |
| 54 | +``` |
| 55 | + |
| 56 | +**Programmatic option:** |
| 57 | +```javascript |
| 58 | +await componentAnalysis(‘pom.xml’, { licenseCheck: false }); |
| 59 | +``` |
| 60 | + |
| 61 | +## CLI Usage |
| 62 | + |
| 63 | +### Get License Information |
| 64 | + |
| 65 | +```bash |
| 66 | +exhort license path/to/pom.xml |
| 67 | +``` |
| 68 | + |
| 69 | +**Example output:** |
| 70 | +```json |
| 71 | +{ |
| 72 | + "manifestLicense": { |
| 73 | + "spdxId": "Apache-2.0", |
| 74 | + "category": "PERMISSIVE", |
| 75 | + "name": "Apache License 2.0", |
| 76 | + "identifiers": ["Apache-2.0"] |
| 77 | + }, |
| 78 | + "fileLicense": { |
| 79 | + "spdxId": "Apache-2.0", |
| 80 | + "category": "PERMISSIVE", |
| 81 | + "name": "Apache License 2.0", |
| 82 | + "identifiers": ["Apache-2.0"] |
| 83 | + }, |
| 84 | + "mismatch": false |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +Note: The `license` command shows only your project's license. For dependency license information, use component analysis. |
| 89 | + |
| 90 | +## Analysis Report Fields |
| 91 | + |
| 92 | +When license checking is enabled, component analysis includes a `licenseSummary` field: |
| 93 | + |
| 94 | +```javascript |
| 95 | +{ |
| 96 | + // ... standard analysis fields (providers, etc.) ... |
| 97 | + "licenseSummary": { |
| 98 | + "projectLicense": { |
| 99 | + "manifest": { |
| 100 | + "spdxId": "Apache-2.0", |
| 101 | + "category": "PERMISSIVE", |
| 102 | + "name": "Apache License 2.0", |
| 103 | + "identifiers": ["Apache-2.0"] |
| 104 | + }, |
| 105 | + "file": { |
| 106 | + "spdxId": "Apache-2.0", |
| 107 | + "category": "PERMISSIVE", |
| 108 | + "name": "Apache License 2.0", |
| 109 | + "identifiers": ["Apache-2.0"] |
| 110 | + }, |
| 111 | + "mismatch": false |
| 112 | + }, |
| 113 | + "incompatibleDependencies": [ |
| 114 | + { |
| 115 | + "purl": "pkg:maven/org.example/gpl-lib@1.0.0", |
| 116 | + "licenses": ["GPL-3.0"], |
| 117 | + "category": "STRONG_COPYLEFT", |
| 118 | + "reason": "Dependency license(s) are incompatible with the project license." |
| 119 | + } |
| 120 | + ] |
| 121 | + } |
| 122 | +} |
| 123 | +``` |
| 124 | + |
| 125 | +**Note:** Dependency license information (for all dependencies, not just incompatible ones) is available in the standard backend response under the `licenses` field. The `licenseSummary` only includes project license details and flagged incompatibilities. |
| 126 | + |
| 127 | +## Common Scenarios |
| 128 | + |
| 129 | +### Mismatch Between Manifest and LICENSE File |
| 130 | + |
| 131 | +If your `package.json` says `"license": "MIT"` but your LICENSE file contains Apache-2.0 text, the component analysis report will show: |
| 132 | +```json |
| 133 | +{ |
| 134 | + "licenseSummary": { |
| 135 | + "projectLicense": { |
| 136 | + "manifest": { |
| 137 | + "spdxId": "MIT", |
| 138 | + "category": "PERMISSIVE", |
| 139 | + "name": "MIT License" |
| 140 | + }, |
| 141 | + "file": { |
| 142 | + "spdxId": "Apache-2.0", |
| 143 | + "category": "PERMISSIVE", |
| 144 | + "name": "Apache License 2.0" |
| 145 | + }, |
| 146 | + "mismatch": true |
| 147 | + }, |
| 148 | + "incompatibleDependencies": [] |
| 149 | + } |
| 150 | +} |
| 151 | +``` |
| 152 | + |
| 153 | +**Action:** Update your manifest or LICENSE file to match. |
| 154 | + |
| 155 | +### Incompatible Dependencies |
| 156 | + |
| 157 | +If you have a permissive-licensed project (MIT, Apache) but depend on GPL-licensed libraries, they’ll appear in `incompatibleDependencies`. |
| 158 | + |
| 159 | +**Action:** Review the flagged dependencies and consider: |
| 160 | +- Finding alternative libraries with compatible licenses |
| 161 | +- Consulting legal counsel if the dependency is necessary |
| 162 | +- Understanding how you’re using the dependency (linking, distribution, etc.) |
| 163 | + |
| 164 | +## SBOM Integration |
| 165 | + |
| 166 | +Project license information is automatically included in generated SBOMs (CycloneDX format) in the root component’s `licenses` field. |
| 167 | + |
| 168 | +**LICENSE file fallback in SBOMs:** |
| 169 | +- **All ecosystems** now include license information in the SBOM when available |
| 170 | +- **Gradle, Go, Python projects**: Even though these ecosystems don’t have manifest license fields, the SBOM will include the license from your LICENSE file |
| 171 | +- **Maven, JavaScript, Rust Cargo projects**: The SBOM uses the manifest license, or falls back to LICENSE file if not specified in manifest |
| 172 | +- If neither manifest nor LICENSE file contains a license, the SBOM root component will have no `licenses` field |
0 commit comments