|
| 1 | +[](https://plugins.gradle.org/plugin/com.github.vlsi.license-gather) |
| 2 | + |
| 3 | +License Gather Plugin |
| 4 | +===================== |
| 5 | + |
| 6 | +The purpose of the plugin is to analyze and infer license names for the dependencies, and verify license compatibility. |
| 7 | +The plugin checks for 3 places: MANIFEST.MF (`Bundle-License` attribute), |
| 8 | +`pom.xml` (`licenses/license` tags), and finally `LICENSE`-like files. |
| 9 | +Note: for now only fuzzy-match is implemented, and by default a similarity threshold of 42% is used. |
| 10 | + |
| 11 | +License Gather Plugin uses https://github.com/spdx/license-list-data for the list of licenses. |
| 12 | + |
| 13 | +Prior art |
| 14 | +--------- |
| 15 | + |
| 16 | +https://github.com/jk1/Gradle-License-Report |
| 17 | + |
| 18 | +Gradle-License-Report is nice (it is), however there are certain pecularities (as of 2019-06-04) |
| 19 | + |
| 20 | +* It can't generate multiple lists within a single project (e.g. license for source / binary artifacts) |
| 21 | +* The model for imported/discovered licenses is differnet |
| 22 | +* There's no way to override license detection |
| 23 | + |
| 24 | +https://github.com/eskatos/honker-gradle |
| 25 | + |
| 26 | +* There's no way to override license files |
| 27 | +* [SPDX](https://spdx.org/licenses/) is not used |
| 28 | + |
| 29 | +License Gather Plugin Features |
| 30 | +------------------------------ |
| 31 | + |
| 32 | +* LICENSE file generation |
| 33 | +* License whitelisting |
| 34 | +* The detected licenses can be overridden |
| 35 | +* Verify license compatibility |
| 36 | +* Type-safe license enumeration (based on SPDX): |
| 37 | + |
| 38 | + com.github.vlsi.gradle.license.api.SpdxLicense.Apache_2_0 |
| 39 | + |
| 40 | +Usage |
| 41 | +----- |
| 42 | + |
| 43 | +Gradle (Groovy DSL): |
| 44 | +```groovy |
| 45 | +import com.github.vlsi.gradle.license.GatherLicenseTask |
| 46 | +import com.github.vlsi.gradle.license.VerifyLicenseCompatibilityTask |
| 47 | +import com.github.vlsi.gradle.release.AsfLicenseCategory |
| 48 | +import com.github.vlsi.gradle.license.api.SpdxLicense |
| 49 | +import com.github.vlsi.gradle.license.api.SimpleLicense |
| 50 | +
|
| 51 | +plugins { |
| 52 | + id('com.github.vlsi.license-gather') version '1.78' |
| 53 | +} |
| 54 | +
|
| 55 | +// Gathers license information and license files from the runtime dependencies |
| 56 | +def gatherLicense = tasks.register('gatherLicense', GatherLicenseTask.class) { |
| 57 | + configurations.add(project.configurations.runtimeClasspath) |
| 58 | +} |
| 59 | +
|
| 60 | +tasks.register("verifyLicenses", VerifyLicenseCompatibilityTask.class) { |
| 61 | + metadata.from(gatherLicense) |
| 62 | + allow(SpdxLicense.EPL_2_0) { |
| 63 | + // The message would be displayed, so the verification results are easier to understand |
| 64 | + because("ISSUE-23: EPL-2.0 is fine in our projects") |
| 65 | + } |
| 66 | + allow(new SimpleLicense("The W3C License", uri("http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/java-binding.zip"))) { |
| 67 | + because("ISSUE-42: John Smith decided the license is OK") |
| 68 | + } |
| 69 | + // License category |
| 70 | + // See https://www.apache.org/legal/resolved.html |
| 71 | + allow(AsfLicenseCategory.A) { |
| 72 | + because("The ASF category A is allowed") |
| 73 | + } |
| 74 | + reject(AsfLicenseCategory.X) { |
| 75 | + because("The ASF category X is forbidden") |
| 76 | + } |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +Gradle (Kotlin DSL): |
| 81 | +```kotlin |
| 82 | +import com.github.vlsi.gradle.license.GatherLicenseTask |
| 83 | +import com.github.vlsi.gradle.license.VerifyLicenseCompatibilityTask |
| 84 | +import com.github.vlsi.gradle.release.AsfLicenseCategory |
| 85 | +import com.github.vlsi.gradle.license.api.SpdxLicense |
| 86 | +import com.github.vlsi.gradle.license.api.SimpleLicense |
| 87 | + |
| 88 | +plugins { |
| 89 | + id("com.github.vlsi.license-gather") version "1.78" |
| 90 | +} |
| 91 | + |
| 92 | +// Gathers license information and license files from the runtime dependencies |
| 93 | +val generateLicense by tasks.registering(GatherLicenseTask::class) { |
| 94 | + configurations.add(project.configurations.runtimeClasspath) |
| 95 | + // In the ideal case, each dependency should ship a copy of the full license text |
| 96 | + // just in case it has been modified. |
| 97 | + // For instance, "MIT licence" and "BSD-* license" are almost always modified, |
| 98 | + // and they have custom "copyright" section. |
| 99 | + // However, certain licenses like Apache-2.0, MPL-2.0, have fixed texts, so |
| 100 | + // we can ignore the failure if project is MPL-2.0 licensed, and it omits the license file |
| 101 | + ignoreMissingLicenseFor.add(SpdxLicense.Apache_2_0.asExpression()) |
| 102 | + |
| 103 | + defaultTextFor.add(SpdxLicense.MPL_2_0.asExpression()) |
| 104 | + |
| 105 | + // Artifact version in override is optional |
| 106 | + overrideLicense("com.thoughtworks.xstream:xstream:1.4.11") { |
| 107 | + // This version reads "BSD style" in pom.xml, however, their license |
| 108 | + // is the same as BSD-3-Clause, so we override it |
| 109 | + // expectedLicense helps to protect from accidental overrides if the project changes version |
| 110 | + expectedLicense = SimpleLicense("BSD style", uri("http://x-stream.github.io/license.html")) |
| 111 | + // https://github.com/x-stream/xstream/issues/151 |
| 112 | + // https://github.com/x-stream/xstream/issues/153 |
| 113 | + effectiveLicense = SpdxLicense.BSD_3_Clause |
| 114 | + } |
| 115 | + |
| 116 | + overrideLicense("com.formdev:svgSalamander") { |
| 117 | + // See https://github.com/blackears/svgSalamander/blob/d6b6fe9a8ece7d0e0e7aeb3de82f027a38a6fe25/www/license/license-bsd.txt |
| 118 | + effectiveLicense = SpdxLicense.BSD_3_Clause |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | +val verifyLicenses by tasks.registering(VerifyLicenseCompatibilityTask::class) { |
| 123 | + metadata.from(gatherLicense) |
| 124 | + // License with SPDX ID (see https://spdx.org/licenses/) |
| 125 | + allow(SpdxLicense.EPL_2_0) { |
| 126 | + // The message would be displayed, so the verification results are easier to understand |
| 127 | + because("ISSUE-23: EPL-2.0 is fine in our projects") |
| 128 | + } |
| 129 | + // A custom license that is not present in SPDX |
| 130 | + allow(SimpleLicense("The W3C License", uri("http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/java-binding.zip"))) { |
| 131 | + because("ISSUE-42: John Smith decided the license is OK") |
| 132 | + } |
| 133 | + // License category |
| 134 | + // See https://www.apache.org/legal/resolved.html |
| 135 | + allow(AsfLicenseCategory.A) { |
| 136 | + // The reason will be displayed |
| 137 | + because("The ASF category A is allowed") |
| 138 | + } |
| 139 | + reject(AsfLicenseCategory.X) { |
| 140 | + because("The ASF category X is forbidden") |
| 141 | + } |
| 142 | +} |
| 143 | +``` |
0 commit comments