Maven: report declared dependencies as direct in static analysis - #1768
Closed
spatten wants to merge 2 commits into
Closed
Maven: report declared dependencies as direct in static analysis#1768spatten wants to merge 2 commits into
spatten wants to merge 2 commits into
Conversation
The pom tactic builds its graph rooted at the project itself, so the project was the only direct dependency and everything it declared was reported as transitive. In a multi-module project the root pom and every submodule were reported as dependencies too. The dynamic tactics already avoid this: Plugin.buildGraph marks the project's own packages direct and shrinkRoots removes them. Static analysis never got the equivalent step, and the TODO marking it as unfinished was dropped in #1331 a week before #1339 added shrinkRoots to the dynamic path. Take the same two steps here. Both are needed: shrinkRoots alone would remove only the root pom and promote the submodules to direct, and a shrink alone would leave a submodule-filtered graph with no direct dependencies at all, because submodule filtering deletes the root pom node without rewiring the edges through it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QrDtxeRNysKQz4NWXixRzU
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QrDtxeRNysKQz4NWXixRzU
Contributor
Author
|
Closing, as this is implemented and merged in #1770 |
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.
Overview
Static Maven analysis reported the project itself as the only direct dependency, and everything the project declared as transitive. In a multi-module project the root pom and every submodule were reported as dependencies too. Analysis using
mvnwas already correct, so this only showed up withoutmvnonPATH, under--static-only-analysis, and in container scanning.The dynamic tactics already handle this:
Plugin.buildGraphmarks the project's own packages direct andshrinkRootsremoves them. Static analysis never got the equivalent step — the TODO marking it as unfinished was deleted in #1331, a week before #1339 addedshrinkRootsto the dynamic path. This takes the same two steps ingetStaticAnalysis.Both steps are needed.
shrinkRootsalone removes only the root pom and would promote the submodules to direct dependencies rather than dropping them. Ashrinkalone leaves a submodule-filtered graph with no direct dependencies at all, because submodule filtering deletes the root pom's node without rewiring the edges through it — which is a second bug this fixes.Acceptance criteria
mvnreports the dependencies it declares as direct, and does not report itself.--only-target 'maven@./:group:module'under static analysis reports that module's dependencies as direct, instead of reporting none.mvnpresent is unchanged.Testing plan
Given a
pom.xmldeclaringjunit:junit:4.13.2andorg.apache.commons:commons-lang3:3.12.0:fossa analyze -o --static-only-analysisand readsourceUnits[0].Build.Imports.["mvn+com.example:demo$1.0"]— the project itself. After: the two declared dependencies.fossa analyze -owithmvnonPATHgives the same two, before and after.For the multi-module case, add two submodules each declaring one dependency. Before,
Importsis the root pom alone and the graph carries all three first-party coordinates; after,Importsis the three declared dependencies and no first-party coordinate appears.cabal test unit-tests --test-options='--match "static analysis of a"'covers all of the above against real pom fixtures. All five fail onmasterwith the symptoms described.Risks
This changes what FOSSA reports for existing projects. Dependencies that were transitive become direct, and the user's own modules stop being reported as dependencies. That is the correction, but it will show as a diff on any project analyzed statically.
The same bug exists in
Strategy/Scala.hs:200, whereanalyzeWithPomscallsPom.analyze'with no shrink. Scala's intent matches Maven's — its dynamic tactics do callshrinkRoots— so its pom fallback is the odd one out there too. Left for a separate PR: it needs an sbt fixture to verify, and the sbt closure's notion of the project's own packages is notclosureSubmodules.Dynamic submodule filtering looks separately broken on
master: on a two-module fixture,--only-targetfor one module returns every dependency and for the other returns none. Untouched here.Metrics
No.
References
Reported internally; no ticket.
Checklist
docs/.docs/README.msand gave consideration to how discoverable or not my documentation is.Changelog.md. If this PR did not mark a release, I added my changes into an## Unreleasedsection at the top..fossa.ymlorfossa-deps.{json.yml}, I updateddocs/references/files/*.schema.jsonAND I have updated example files used byfossa initcommand. You may also need to update these if you have added/removed new dependency type (e.g.pip) or analysis target type (e.g.poetry).docs/references/subcommands/<subcommand>.md.🤖 Generated with Claude Code
https://claude.ai/code/session_01QrDtxeRNysKQz4NWXixRzU