Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Problem with MultiLicenseInfo fields access in dependency-license-report 2.1 #239

Closed
altro3 opened this issue May 8, 2022 · 0 comments

Comments

@altro3
Copy link
Contributor

altro3 commented May 8, 2022

I tried to use my custom Reporter:

class SpdxReporter(val dest: File) : ReportRenderer {
    // License names to their SPDX identifier
    val spdxIds = mapOf(
        "Apache License, Version 2.0" to "Apache-2.0",
        "The Apache Software License, Version 2.0" to "Apache-2.0",
        "BSD Zero Clause License" to "0BSD",
        "Eclipse Public License 2.0" to "EPL-2.0",
        "Eclipse Public License v. 2.0" to "EPL-2.0",
        "GNU General Public License, version 2 with the GNU Classpath Exception" to "GPL-2.0 WITH Classpath-exception-2.0",
        "COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0" to "CDDL-1.0"
    )

    private fun quote(str: String) : String {
        return if (str.contains(',') || str.contains("\"")) {
            "\"" + str.replace("\"", "\"\"") + "\""
        } else {
            str
        }
    }

    override fun render(data: ProjectData?) {
        dest.parentFile.mkdirs()
        FileWriter(dest).use { out ->
            out.append("name,url,version,revision,license\n")
            data?.allDependencies?.forEach { dep ->
                val info = com.github.jk1.license.render.LicenseDataCollector.multiModuleLicenseInfo(dep)

                val depVersion = dep.version
                val depName = dep.group + ":" + dep.name
                val depUrl = info.moduleUrls.first()

                val licenseIds = info.licenses.mapNotNull { license ->
                    license.name?.let {
                        checkNotNull(spdxIds[it]) { "No SPDX identifier for $license" }
                    }
                }.toSet()

                // Combine multiple licenses.
                // See https://spdx.github.io/spdx-spec/appendix-IV-SPDX-license-expressions/#composite-license-expressions
                val licenseId = licenseIds.joinToString(" OR ")
                out.append("${quote(depName)},${quote(depUrl)},${quote(depVersion)},,${quote(licenseId)}\n")
            }
        }
    }
}

It works fine with version 1.+, but I have problem when try to upgrade plugin to last version:
изображение
Problem with fields moduleUrls and licenses. Gradle tell me that I haven't access :

e: D:\Work\contrib\java-client\build.gradle.kts:263:35: Cannot access 'moduleUrls': it is public in '<anonymous>'
e: D:\Work\contrib\java-client\build.gradle.kts:265:39: Cannot access 'licenses': it is public in '<anonymous>'
@altro3 altro3 changed the title [bug] Problem with dependency-license-report 2.1 [bug] Problem with MultiLicenseInfo fields access in dependency-license-report 2.1 May 8, 2022
@jk1 jk1 closed this as completed in a17d25f Jul 2, 2022
jk1 added a commit that referenced this issue Jul 2, 2022
Actualization libs versions. Gradle 7.4.2 Fix #239
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant