cashapp / licensee

Gradle plugin which validates the licenses of your dependency graph match what you expect
https://cashapp.github.io/licensee/docs/1.x/
Apache License 2.0
637 stars 30 forks source link

Allow configuration of sources when determining licenses #377

Open TheMrMilchmann opened 1 week ago

TheMrMilchmann commented 1 week ago

Currently, Licensee prefers the URL of license POM entries to determine the correct SPDX entry. From what I understood, this decision was made based on practicality because the data suggested that it would lead to better results at the time. Though, technically, this is incorrect as the license name should usually be an SPDX identifier while the URL can be arbitrary. From my experience, this is the wrong default for projects, I am working on. I'm not the first person to express interest in matching by name and this has been brought up numerous times on the issue tracker and Slack before. In fact, this has even caused some projects to omit the license URL altogether.

To rectify this unfortunate default (without breaking compatibility for current users), I propose to make the sources used to determine the license configurable. This is an implementation of the behavior I initially described in https://github.com/cashapp/licensee/issues/137#issuecomment-2040395611:

I propose to expose an API that the build author may use to tune the strategy. Specifically, we can mimic the API for configuring metadata sources for repositories. This could look as follows (exact names and syntax are tbd):

licensee {
    licenseSources {       // 1
        licenseName()      // 2
        licenseUrl()       // 3
    }
}

We introduce a LicenseSources interface that may be used to configure the sources from which to infer license information. In the DSL, this is exposed under the licensee extension (1). The interface defines several methods that may be used to enable certain sources of information. Initially, those would use be license name (2) and license URL (3), but additional sources could be added in the future without breaking configuration or introducing needless complexity.

licenseSources would be a regular function under the licensee extension and probably have the signature fun licenseSources(action: Action<LicenseSources>). If the function is not called, we resort to the current behavior as default.

As an added benefit, we could allow the build author to call licenseSources {} (without adding any sources) to indicate that all license mappings must be specified explicitly. However, I suggest deferring this decision and treating it as a configuration mistake for now.

I'm aware that documentation is missing and there is probably some more room for improvements but I'm reaching out now to check if there even is interest in merging this feature.