Detect licenses from Maven pom.xml comments - #5249
Draft
chrisrueger wants to merge 1 commit into
Draft
Conversation
Fat/uber JAR scans could miss Maven licenses when embedded META-INF/maven/**/pom.xml files omitted <licenses> and only documented licensing in XML comments. This change adds an offline fallback that extracts license signals from POM comments before attempting parent POM resolution. Signed-off-by: Christoph Rueger <chrisrueger@gmail.com> Co-Authored-By: chrisrueger <188422+chrisrueger@users.noreply.github.com> Co-Authored-By: Copilot <198982749+Copilot@users.noreply.github.com>
chrisrueger
force-pushed
the
copilot/detect-licenses-from-comments
branch
from
September 3, 2026 17:11
ceedace to
5cf1e9e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fat/uber JAR scans could miss Maven licenses when embedded
META-INF/maven/**/pom.xmlfiles omitted<licenses>and only documented licensing in XML comments. This change adds an offline fallback that extracts license signals from POM comments before attempting parent POM resolution.Disclaimer Note on my use of AI: I used Copilot to come up with this PR.
Take it as a base for discussion. I am not experienced with go (comming from the Java world), but I managed to do some some step debugging in VSCode. I will run it against our own project where I identified the issues with the pom.xml
I have no clue how bad / sloppy this go code is but I will try to be helpful comming up with a better solution with help you.
For example I wonder if the regex parsing of the license is already solved in the codebase somewhere and if this PR reinvents the wheel. Just let me know or use the PR as base.
Comment-based license fallback
Resolution order
<licenses>as the first and authoritative sourceScope control
Type of change
Checklist
Issue references
Fixes #5248
Summary (Copilot)
This pull request enhances Maven POM license detection by extracting license information from XML comments when structured license data is missing. It introduces a new parser for license comments, updates the main parser logic to use it, and adds comprehensive tests to ensure accuracy and preference for structured data when available.
License extraction improvements:
ExtractLicensesFromCommentsincomment_license_parser.goto detect and extract SPDX license IDs and URLs from XML comments in POM files, using regex patterns and mappings to known licenses.pomProjectByParentPathinarchive_parser.goto enrich missing license data by extracting licenses from XML comments if the structured<licenses>block is empty or missing.Testing and validation:
comment_license_parser_test.go, covering detection, ignoring non-license URLs, and preferring structured licenses over comment-based detection.archive_parser_test.goto verify that license extraction from comments works as expected within the archive parsing workflow.Internal refactoring:
pom_parser.goto read the entire file content for charset detection and to facilitate comment-based license extraction. [1] [2] [3]