jaredsburrows / gradle-license-plugin

Gradle plugin that provides a task to generate a HTML license report of your project.
https://central.sonatype.com/artifact/com.jaredsburrows/gradle-license-plugin
Apache License 2.0
406 stars 65 forks source link

The report generates non deterministic results because of the sorting method used #491

Closed francescocervone closed 4 months ago

francescocervone commented 4 months ago

Context and description

Looking at the plugin source code, it seems that dependencies are sorted by the project name, which in some cases can be exactly the same. For instance, almost every time we update any dependency in our app, we get this kind of change in the PR:

Screenshot 2024-05-06 at 14 45 41

Both dependencies espresso-idling-resource and idling-concurrent share the same project name AndroidX Test Library.

Proposed solution

I was thinking, does it make sense to you to have a sorting mechanism based on two keys as fallback? Something like:

projects.sortWith(compareBy({ it.name.lowercase(Locale.getDefault()) }, { it.dependency }))

Where it.dependency is just group:module:version, which is supposed to be unique. This should generate a deterministic result.

I honestly don't understand why the result is non deterministic in the first place, but this should fix the issue.

We're just using the JSON report, but I guess the suggested resolution would be beneficial for every kind of report, given that the sorting here happens at the task level, and not the report level.