Skip to content

Allow project-specific license file overrides#107

Open
rombirli wants to merge 6 commits intomasterfrom
rombirli/license-generator-dependency-overrides
Open

Allow project-specific license file overrides#107
rombirli wants to merge 6 commits intomasterfrom
rombirli/license-generator-dependency-overrides

Conversation

@rombirli
Copy link
Contributor

No description provided.

@rombirli rombirli marked this pull request as ready for review March 13, 2026 09:28
@rombirli rombirli requested a review from mstachniuk March 13, 2026 09:29
Copy link
Contributor

@mstachniuk mstachniuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not approving it as this contributions shows hidden issue in current logic. It will be great that @jonas-wielage-sonarsource (as first author) will look on that more deeply.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the comment to keep it up to date

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Updated in efc7a8d

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally speaking, I like the contribution and possibility to override/configure the task.
However, looking how you are using it https://github.com/SonarSource/sonar-apex/pull/184/changes#diff-d146424e9fbbf2e55c7c4d66cf3c6fdbb2a6b2b37ee15e7113994fb8654a4f0b

licenseGenerationConfig {
    projectLicenseFile.set(file("../LICENSE.txt"))
    dependencyLicenseOverrides.put("com.salesforce:apex-jorje-lsp-minimized", file("../build-logic/common/gradle-modules/src/main/resources/licenses/BSD-3.txt"))
    dependencyLicenseOverrides.put("org.codehaus.woodstox:stax2-api", file("../build-logic/common/gradle-modules/src/main/resources/licenses/BSD-2.txt"))
}

shows that there is some issue in existing logic, because org.codehaus.woodstox.stax2-api is already on the list and e.x. in sonar-go the wrong license is chosen: https://github.com/SonarSource/sonar-go-enterprise/blob/19952be1ac2d0f5de5f7b026a3b99edff11f4351/private/sonar-go-enterprise-plugin/src/main/resources/licenses/THIRD_PARTY_LICENSES/org.codehaus.woodstox.stax2-api-LICENSE.txt

@jonas-wielage-sonarsource would you like to investigate?

IMO there should be one mechanism for fixing invalid license information (with smart default), and the one that is configurable is better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running the task I miss the logging on --info level: what license were chosen and why. Currently there are only logs from Gradle-License-Report.

Copy link
Contributor Author

@rombirli rombirli Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running the task I miss the logging on --info level: what license were chosen and why. Currently there are only logs from Gradle-License-Report.

I added the missing logs in 24f58e1

The added logs look like (example from sonar-apex)

Importing external dependency data. A total of 0 configured.
Applying dependency filters. A total of 0 configured.
Building report for project sonar-apex-plugin
com.eclipsesource.minimal-json:minimal-json: used bundled resource 'MIT.txt' for POM license 'MIT License'
com.fasterxml.woodstox:woodstox-core: used bundled resource 'Apache-2.0.txt' for POM license 'The Apache License, Version 2.0'
com.google.code.findbugs:jsr305: used bundled resource 'Apache-2.0.txt' for POM license 'The Apache Software License, Version 2.0'
com.salesforce:apex-jorje-lsp-minimized: used configured override 'BSD-3.txt'
commons-codec:commons-codec: copied packaged license 'commons-codec-1.18.0.jar/META-INF/LICENSE.txt'
javax.annotation:javax.annotation-api: copied packaged license 'javax.annotation-api-1.3.2.jar/META-INF/LICENSE.txt'
org.codehaus.woodstox:stax2-api: used configured override 'BSD-2.txt'
org.sonarsource.analyzer-commons:sonar-analyzer-commons: used bundled resource 'GNU-LGPL-3.txt' for POM license 'GNU LGPL 3'
org.sonarsource.analyzer-commons:sonar-xml-parsing: used bundled resource 'GNU-LGPL-3.txt' for POM license 'GNU LGPL 3'
xerces:xercesImpl: copied packaged license 'xercesImpl-2.12.2.jar/META-INF/LICENSE'
xml-apis:xml-apis: copied packaged license 'xml-apis-1.4.01.jar/license/LICENSE'
Dependency license report for project sonar-apex-plugin created in C:\Users\romain.birling\Documents\sonar-apex\sonar-apex-plugin\build\reports\dependency-license
Stored cache entry for task ':sonar-apex-plugin:generateLicenseReport' with cache key a28909eb19b13b44b2b4af78d0fccf12
Resolve mutations for :sonar-apex-plugin:generateLicenseResources (Thread[#613,included builds,5,main]) started.
:sonar-apex-plugin:generateLicenseResources (Thread[#613,included builds,5,main]) started.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shows that there is some issue in existing logic, because org.codehaus.woodstox.stax2-api is already on the list and e.x. in sonar-go the wrong license is chosen

I proposed a fix for this problem in a09a260


@Throws(IOException::class)
private fun copyOverriddenLicense(data: ModuleData): Status {
val dependencyKey = "${data.group}:${data.name}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the : as separator, most probably we should adapt values in dependenciesWithUnusableLicenseFileInside and logic in copyIncludedLicenseFromDependency()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in ba3de29

@rombirli rombirli force-pushed the rombirli/license-generator-dependency-overrides branch from b2bd9cf to 24f58e1 Compare March 13, 2026 14:35
@sonarqube-next
Copy link

Quality Gate failed Quality Gate failed for 'cloud-native-gradle-modules'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube

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

Successfully merging this pull request may close these issues.

2 participants