jk1/Gradle-License-Report

It would be nice if the inventory report had a "multiple licenses" section

Vampire opened this issue · 1 comments

If a dependency has multiple licenses detected, this can basically mean four things.
Either the code is dual-licensed under both licenses (for example net.java.dev.jna:jna:5.6.0),
or the parent POM is covered by one license and the POM itself is covered by another license (for example org.ow2.asm:asm:9.6),
or some parts are covered by one license and other parts are covered by another license (for example org.jacoco:org.jacoco.report:0.8.11),
or some license detection rules are erroneous (for example org.hamcrest:hamcrest:2.2).

In any case, you most probably have to have a deeper look into those cases and evaluate on a case-by-case basis what the situation is, so it would be nice to have a section that lists all dependencies that have multiple licenses detected in the inventory HTML report to have a work-list to go through.

Here a way to add this information as first section by customization using Kotlin:

class EnhancedInventoryHtmlReportRenderer : InventoryHtmlReportRenderer() {
    override fun buildLicenseInventory(data: ProjectData): Map<String, List<ModuleData>> {
        val inventory = super.buildLicenseInventory(data)
        inventory[" Multiple Licenses"] = inventory
            .flatMap { (license, modules) ->
                modules.map { license to it }
            }
            .groupBy({ it.second }) { it.first }
            .filter { it.value.size > 1 }
            .map { it.key }
        return inventory
    }

    fun section(label: String, value: String) = """
        <label>$label</label>
        <div class='dependency-value'>$value</div>
    """.trimIndent()

    fun link(name: String, url: String) = "<a href='$url'>$name</a>"
}