fix(maven): resolve version ranges in component analysis#536
Open
Strum355 wants to merge 1 commit into
Open
Conversation
Maven version ranges (e.g. `[1.2.17,1.3.0)`) in pom.xml dependencies are preserved verbatim by `mvn help:effective-pom`, which is used for component analysis. The backend cannot look up vulnerabilities for a range-valued purl like `pkg:maven/log4j/log4j@[1.2.17,1.3.0)`, so these dependencies were silently dropped from analysis results. Stack analysis was unaffected because it uses `mvn dependency:tree` which resolves ranges to concrete versions. Add `#resolveVersionRanges` to detect range-valued versions in the effective POM output and resolve them by running `mvn dependency:tree -DoutputType=text -Dscope=compile`, parsing the direct dependencies (depth 1) to extract the concrete versions Maven selects. The resolution is guarded: it only runs when at least one dependency has a version range, and falls back to the original range values if the tree invocation fails. Ref: fabric8-analytics/fabric8-analytics-vscode-extension#812 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reviewer's GuideAdds Maven version range resolution for component analysis by invoking maven-dependency-plugin:tree, and adjusts the shared dependency-tree depth logic plus tests/fixtures to cover version ranges. Sequence diagram for Maven version range resolution in component analysissequenceDiagram
participant Java_maven
participant Base_Java
participant Maven
Java_maven->>Java_maven: #getSbomForComponentAnalysis(manifestPath, opts)
Java_maven->>Java_maven: #getDependencies(tmpEffectivePom)
Java_maven->>Java_maven: #resolveVersionRanges(dependencies, manifestPath, opts)
alt [dependency has version range]
Java_maven->>Java_maven: selectToolBinary(manifestPath, opts)
Java_maven->>Maven: _invokeCommand(mvn, maven-dependency-plugin:tree)
Maven-->>Java_maven: mvn_deptree_ranges.txt
Java_maven->>Java_maven: parseDep(line)
Java_maven->>Base_Java: _getDepth(line)
Base_Java-->>Java_maven: depth
Java_maven->>Java_maven: #isVersionRange(dep.version)
Java_maven->>Java_maven: replace dep.version with resolved version
else [no version range or failure]
Java_maven-->>Java_maven: return original dependencies
end
Java_maven->>Java_maven: toPurl(groupId, artifactId, version)
Java_maven-->>Java_maven: sbom
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
3 tasks
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.
Summary
Maven version ranges (e.g.
[1.2.17,1.3.0),(1.0,2.0]) inpom.xmldependency versions are preserved verbatim bymvn help:effective-pom. Component analysis uses the effective POM to extract dependency versions, so range expressions end up as the version in the PackageURL (e.g.pkg:maven/log4j/log4j@[1.2.17,1.3.0)). The backend cannot look up vulnerabilities for a range-valued purl, so these dependencies are silently dropped — no editor diagnostics appear for them.Stack analysis is unaffected because it uses
mvn dependency:tree, which resolves ranges to concrete versions before output.How it works
After extracting dependencies from the effective POM,
#resolveVersionRangeschecks whether any dependency has a version range (starts with[or(). If none do, it returns immediately — no performance impact for normal projects.When ranges are detected, it runs
mvn dependency:tree -DoutputType=text -Dscope=compile(without-Dverboseorclean, unlike stack analysis) and parses the direct dependencies (depth 1) from the text output. Each resolvedgroupId:artifactId → versionmapping is collected, and range-valued versions in the dependency list are replaced with the concrete resolved versions before SBOM generation.If the dependency tree invocation fails for any reason, the method logs (when debug is enabled) and falls back to the original unresolved versions, so the overall flow is never broken.
Changes
src/providers/java_maven.js— Add#isVersionRangeand#resolveVersionRangesprivate methods. Call#resolveVersionRangesin#getSbomForComponentAnalysisafter filtering ignored deps.src/providers/base_java.js— Harden_getDepth(renamed from#getDepth, now protected) to handle root lines (depth 0) and empty strings, making it safe to call from subclasses on full dependency tree output.test/providers/java_maven.test.js— Addpom_deps_with_version_rangetest case.test/providers/tst_manifests/maven/pom_deps_with_version_range/— New fixture with range-valued dependency (log4j [1.2.17,1.3.0)) and concrete dependency (snappy-java 1.1.10.0), verifying both stack and component analysis resolve the range to1.2.17.Test plan
[12.0.1,12.0.9)for jetty-server — diagnostics now appearRef: fabric8-analytics/fabric8-analytics-vscode-extension#812
🤖 Generated with Claude Code
Summary by Sourcery
Resolve Maven dependency version ranges during component analysis so SBOMs use concrete versions and previously dropped dependencies receive diagnostics.
Bug Fixes:
Enhancements: