|
| 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., `pom.xml`, `package.json`, `Cargo.toml`) 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 | + - `pom.xml`: `<licenses><license><name>` element |
| 22 | + - `package.json`: `license` field (or legacy `licenses` array) |
| 23 | + - `Cargo.toml`: `package.license` field |
| 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, 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 (`POST /api/v5/licenses/identify`) is used for more accurate LICENSE file detection when available. |
| 36 | + |
| 37 | +### Compatibility Checking |
| 38 | + |
| 39 | +The client checks if dependency licenses are compatible with your project license using a restrictiveness hierarchy: |
| 40 | + |
| 41 | +``` |
| 42 | +PERMISSIVE (1) < WEAK_COPYLEFT (2) < STRONG_COPYLEFT (3) |
| 43 | +``` |
| 44 | + |
| 45 | +- If a dependency's license is **more restrictive** than the project → **INCOMPATIBLE** |
| 46 | +- If a dependency's license is **equal or less restrictive** → **COMPATIBLE** |
| 47 | +- If either license category is **UNKNOWN** → **UNKNOWN** |
| 48 | + |
| 49 | +Examples: |
| 50 | +- Permissive project (MIT) + permissive dependency (Apache-2.0) → Compatible |
| 51 | +- Permissive project (MIT) + strong copyleft dependency (GPL-3.0) → Incompatible |
| 52 | +- Strong copyleft project (GPL-3.0) + permissive dependency (MIT) → Compatible |
| 53 | + |
| 54 | +## Configuration |
| 55 | + |
| 56 | +### Disable License Checking |
| 57 | + |
| 58 | +License analysis runs automatically during **component analysis only** (not stack analysis). To disable it: |
| 59 | + |
| 60 | +**Environment variable:** |
| 61 | +```bash |
| 62 | +export TRUSTIFY_DA_LICENSE_CHECK=false |
| 63 | +``` |
| 64 | + |
| 65 | +**Java property:** |
| 66 | +```java |
| 67 | +System.setProperty("TRUSTIFY_DA_LICENSE_CHECK", "false"); |
| 68 | +``` |
| 69 | + |
| 70 | +## CLI Usage |
| 71 | + |
| 72 | +### License Command |
| 73 | + |
| 74 | +Display project license information from manifest and LICENSE file: |
| 75 | + |
| 76 | +```bash |
| 77 | +java -jar trustify-da-java-client-cli.jar license /path/to/pom.xml |
| 78 | +``` |
| 79 | + |
| 80 | +**Example output:** |
| 81 | +```json |
| 82 | +{ |
| 83 | + "manifestLicense": { |
| 84 | + "spdxId": "Apache-2.0", |
| 85 | + "details": { |
| 86 | + "identifiers": [ |
| 87 | + { |
| 88 | + "id": "Apache-2.0", |
| 89 | + "name": "Apache License 2.0", |
| 90 | + "isDeprecated": false, |
| 91 | + "isOsiApproved": true, |
| 92 | + "isFsfLibre": true, |
| 93 | + "category": "PERMISSIVE" |
| 94 | + } |
| 95 | + ], |
| 96 | + "expression": "Apache-2.0", |
| 97 | + "name": "Apache License 2.0", |
| 98 | + "category": "PERMISSIVE", |
| 99 | + "source": "SPDX", |
| 100 | + "sourceUrl": "https://spdx.org" |
| 101 | + } |
| 102 | + }, |
| 103 | + "mismatch": false |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +> Note: `fileLicense` is omitted when null. The `license` command shows only your project's license. For dependency license compatibility, use component analysis. |
| 108 | +
|
| 109 | +### Component Analysis with License Summary |
| 110 | + |
| 111 | +When running component analysis, the license summary is automatically included in the output: |
| 112 | + |
| 113 | +```bash |
| 114 | +java -jar trustify-da-java-client-cli.jar component /path/to/pom.xml |
| 115 | +``` |
| 116 | + |
| 117 | +## Programmatic Usage |
| 118 | + |
| 119 | +```java |
| 120 | +import io.github.guacsec.trustifyda.ComponentAnalysisResult; |
| 121 | +import io.github.guacsec.trustifyda.impl.ExhortApi; |
| 122 | +import io.github.guacsec.trustifyda.license.LicenseCheck.LicenseSummary; |
| 123 | + |
| 124 | +ExhortApi api = new ExhortApi(); |
| 125 | + |
| 126 | +// Run component analysis with license check |
| 127 | +ComponentAnalysisResult result = api.componentAnalysisWithLicense("/path/to/pom.xml").get(); |
| 128 | + |
| 129 | +// Access the analysis report |
| 130 | +var report = result.report(); |
| 131 | + |
| 132 | +// Access the license summary |
| 133 | +LicenseSummary licenseSummary = result.licenseSummary(); |
| 134 | +if (licenseSummary != null) { |
| 135 | + // Project license info |
| 136 | + var projectLicense = licenseSummary.projectLicense(); |
| 137 | + System.out.println("Mismatch: " + projectLicense.mismatch()); |
| 138 | + |
| 139 | + // Incompatible dependencies |
| 140 | + for (var dep : licenseSummary.incompatibleDependencies()) { |
| 141 | + System.out.println("Incompatible: " + dep.purl() + " - " + dep.licenses()); |
| 142 | + } |
| 143 | +} |
| 144 | + |
| 145 | +// Or use componentAnalysis() without license check (original API, unchanged) |
| 146 | +var reportOnly = api.componentAnalysis("/path/to/pom.xml").get(); |
| 147 | +``` |
| 148 | + |
| 149 | +## License Summary Fields |
| 150 | + |
| 151 | +The `LicenseSummary` returned in `ComponentAnalysisResult.licenseSummary()` contains: |
| 152 | + |
| 153 | +| Field | Type | Description | |
| 154 | +|-------|------|-------------| |
| 155 | +| `projectLicense` | `ProjectLicenseSummary` | Project license from manifest and LICENSE file | |
| 156 | +| `incompatibleDependencies` | `List<IncompatibleDependency>` | Dependencies with incompatible licenses | |
| 157 | +| `error` | `String` | Error message if license check partially failed | |
| 158 | + |
| 159 | +**ProjectLicenseSummary:** |
| 160 | + |
| 161 | +| Field | Type | Description | |
| 162 | +|-------|------|-------------| |
| 163 | +| `manifest` | `JsonNode` | Full license details from backend for the manifest license (includes identifiers, category, name, source) | |
| 164 | +| `file` | `JsonNode` | Full license details from backend for the LICENSE file license | |
| 165 | +| `mismatch` | `boolean` | True if manifest and file licenses differ | |
| 166 | + |
| 167 | +**IncompatibleDependency:** |
| 168 | + |
| 169 | +| Field | Type | Description | |
| 170 | +|-------|------|-------------| |
| 171 | +| `purl` | `String` | Package URL of the dependency | |
| 172 | +| `licenses` | `List<LicenseIdentifier>` | Full license identifier objects (id, name, category, isDeprecated, isOsiApproved, isFsfLibre) | |
| 173 | +| `category` | `LicenseCategory` | License category | |
| 174 | +| `reason` | `String` | Explanation of the incompatibility | |
| 175 | + |
| 176 | +## SBOM Integration |
| 177 | + |
| 178 | +Project license information is automatically included in generated CycloneDX SBOMs on the root component: |
| 179 | + |
| 180 | +```json |
| 181 | +{ |
| 182 | + "metadata": { |
| 183 | + "component": { |
| 184 | + "type": "application", |
| 185 | + "name": "my-project", |
| 186 | + "version": "1.0.0", |
| 187 | + "licenses": [ |
| 188 | + { "license": { "id": "Apache-2.0" } } |
| 189 | + ] |
| 190 | + } |
| 191 | + } |
| 192 | +} |
| 193 | +``` |
| 194 | + |
| 195 | +- **All ecosystems** include license information in the SBOM when available |
| 196 | +- License names are resolved to valid SPDX identifiers using the CycloneDX license resolver |
| 197 | +- If neither manifest nor LICENSE file contains a license, the SBOM root component will have no `licenses` field |
| 198 | + |
| 199 | +## Common Scenarios |
| 200 | + |
| 201 | +### Mismatch Between Manifest and LICENSE File |
| 202 | + |
| 203 | +If your `pom.xml` says `Apache-2.0` but your LICENSE file contains MIT text: |
| 204 | + |
| 205 | +```json |
| 206 | +{ |
| 207 | + "projectLicense": { |
| 208 | + "manifest": { |
| 209 | + "expression": "Apache-2.0", |
| 210 | + "category": "PERMISSIVE" |
| 211 | + }, |
| 212 | + "file": { |
| 213 | + "expression": "MIT", |
| 214 | + "category": "PERMISSIVE" |
| 215 | + }, |
| 216 | + "mismatch": true |
| 217 | + } |
| 218 | +} |
| 219 | +``` |
| 220 | + |
| 221 | +**Action:** Update your manifest or LICENSE file to match. |
| 222 | + |
| 223 | +### Incompatible Dependencies |
| 224 | + |
| 225 | +If you have a permissive-licensed project (e.g., Apache-2.0) but depend on copyleft-licensed libraries: |
| 226 | + |
| 227 | +```json |
| 228 | +{ |
| 229 | + "incompatibleDependencies": [ |
| 230 | + { |
| 231 | + "purl": "pkg:maven/org.mariadb.jdbc/mariadb-java-client@3.1.4", |
| 232 | + "licenses": [ |
| 233 | + { |
| 234 | + "id": "LGPL-2.1", |
| 235 | + "name": "GNU Lesser General Public License v2.1 only", |
| 236 | + "isDeprecated": true, |
| 237 | + "isOsiApproved": true, |
| 238 | + "isFsfLibre": true, |
| 239 | + "category": "WEAK_COPYLEFT" |
| 240 | + } |
| 241 | + ], |
| 242 | + "category": "WEAK_COPYLEFT", |
| 243 | + "reason": "Dependency license(s) are incompatible with the project license." |
| 244 | + } |
| 245 | + ] |
| 246 | +} |
| 247 | +``` |
| 248 | + |
| 249 | +**Action:** Review the flagged dependencies and consider finding alternatives with compatible licenses. |
0 commit comments