Skip to content

Commit c4b4e32

Browse files
committed
Add documentation
1 parent 8c336ed commit c4b4e32

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,63 @@ Optionally, run this command with `--global` to apply this configuration globall
5151
* Go-related tasks are automatically linked to `test`, `assemble`, `check`, and `build` tasks
5252
* A configuration `goBinaries` is created, and it can be used to depend on the Go binaries like
5353
`implementation(projects(":go-subprojcet", "goBinaries"))`
54+
55+
## Generating license files for a plugin
56+
57+
The `license-file-generator` plugin generates license files for third-party runtime dependencies and bundles them into the plugin's resources folder.
58+
59+
### Setup
60+
61+
Apply the plugin to the subproject that packages the plugin (usually `sonar-<language>-plugin`):
62+
```kotlin
63+
plugins {
64+
id("org.sonarsource.cloud-native.license-file-generator")
65+
}
66+
```
67+
68+
### Configuration
69+
70+
The plugin exposes a `licenseGenerationConfig` extension with the following options:
71+
72+
| Property | Type | Default | Description |
73+
|------------------------------|---------------------|-----------------------------------------------------------------|--------------------------------------------------------------------------|
74+
| `projectLicenseFile` | `File` | `../LICENSE.txt` (one level above the plugin project directory) | The project's own license file. |
75+
| `dependencyLicenseOverrides` | `Map<String, File>` | empty | Per-dependency license file overrides. Keys use the `group:name` format. |
76+
77+
Example configuration (Groovy DSL):
78+
```groovy
79+
licenseGenerationConfig {
80+
projectLicenseFile.set(file("../LICENSE.txt"))
81+
dependencyLicenseOverrides.put("com.salesforce:apex-jorje-lsp-minimized", file("../build-logic/common/gradle-modules/src/main/resources/licenses/BSD-3.txt"))
82+
}
83+
```
84+
85+
Example configuration (Kotlin DSL):
86+
```kotlin
87+
licenseGenerationConfig {
88+
projectLicenseFile.set(file("../LICENSE.txt"))
89+
dependencyLicenseOverrides.put("com.salesforce:apex-jorje-lsp-minimized", file("../build-logic/common/gradle-modules/src/main/resources/licenses/BSD-3.txt"))
90+
}
91+
```
92+
93+
Use `dependencyLicenseOverrides` when the plugin cannot automatically resolve the correct license for a dependency (e.g., the dependency jar does not include a license file and its POM license title is not recognized).
94+
95+
### Available bundled license files
96+
97+
The following license files are bundled in this module and can be referenced in overrides:
98+
`0BSD.txt`, `Apache-2.0.txt`, `BSD-2.txt`, `BSD-3.txt`, `GNU-LGPL-3.txt`, `Go.txt`, `lgpl-2.1.txt`, `MIT.txt`
99+
100+
### Tasks
101+
102+
| Task | Description |
103+
|----------------------------|---------------------------------------------------------------------------------------------------------------|
104+
| `generateLicenseReport` | Generates license files into the build directory. |
105+
| `generateLicenseResources` | Copies generated license files to `src/main/resources/licenses/`. Run this to update committed license files. |
106+
| `validateLicenseFiles` | Validates that committed license files match the generated ones. Runs as part of `check`. |
107+
108+
### Workflow
109+
110+
1. Apply the plugin and configure `licenseGenerationConfig` if needed
111+
2. Run `./gradlew generateLicenseResources` to generate and copy license files into `src/main/resources/licenses/`
112+
3. Commit the generated files
113+
4. The `check` task will automatically validate that committed license files are up-to-date via `validateLicenseFiles`

gradle-modules/src/main/kotlin/org/sonarsource/cloudnative/gradle/AnalyzerLicensingPackagingRenderer.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,11 @@ class AnalyzerLicensingPackagingRenderer(
160160
}
161161

162162
copyLicenseFile(data, buildOutputDir.resolve(licenseFileDetails.get().file))
163-
logger.info("For the dependency {}: copied packaged license from '{}'",
164-
data.dependencyKey(), licenseFileDetails.get().file)
163+
logger.info(
164+
"For the dependency {}: copied packaged license from '{}'",
165+
data.dependencyKey(),
166+
licenseFileDetails.get().file
167+
)
165168
return Status.success
166169
}
167170

@@ -172,10 +175,14 @@ class AnalyzerLicensingPackagingRenderer(
172175
return Status.failure("No license found in pom data.")
173176
}
174177
val pomLicense = licenses[0]
175-
if(licenses.size > 1) {
176-
logger.warn("The dependency: {}: contains multiple licenses in pom data: [{}]. The '{}' was taken. " +
177-
"Please review if it is the correct one, if not define it in licenseGenerationConfig.dependencyLicenseOverrides",
178-
data.dependencyKey(), licenses.joinToString { it.name }, pomLicense.name)
178+
if (licenses.size > 1) {
179+
logger.warn(
180+
"The dependency: {}: contains multiple licenses in pom data: [{}]. The '{}' was taken. " +
181+
"Please review if it is the correct one, if not define it in licenseGenerationConfig.dependencyLicenseOverrides",
182+
data.dependencyKey(),
183+
licenses.joinToString { it.name },
184+
pomLicense.name
185+
)
179186
}
180187

181188
return copyLicenseFromResources(data, pomLicense.name)

0 commit comments

Comments
 (0)