Safeguard
Developer Tools•

How do I list transitive dependencies in npm, Maven, Cargo and .NET?

Each package manager can print the full dependency tree, transitive packages included. Here are the commands for npm, Maven, Cargo, Go and .NET today.

Safeguard Security Team
3 min read

Every major package manager can print its full dependency tree, including transitive packages. Use npm ls with the all option, the Maven dependency plugin's tree goal, cargo tree, go list with the all pattern, or dotnet list package with the transitive option. Run the one for your stack, then feed the result to a scanner.

Definitions

Transitive dependency. A package you did not declare that arrives because a dependency needs it.

Dependency tree. The nested view of what depends on what.

Depth. How many levels from your project a package sits.

Commands by ecosystem

EcosystemCommandWhat to know
npmnpm ls --allDefault depth is 1. The all option shows every level
Mavenmvn dependency:treeVerbose mode shows nodes removed by conflict resolution
Cargocargo treePackages marked with an asterisk were shown earlier
Gogo list -m allPrints the selected module versions for the build
.NETdotnet list package --include-transitiveTransitive is not the default
npm ls --all
mvn dependency:tree -Dverbose=true
cargo tree
go list -m all
dotnet list package --include-transitive

Notes on each

The npm docs say the tree is the logical dependency graph, not the physical layout of node_modules. A package lock option lists the tree from the lockfile instead of the installed folder.

Maven's tree goal can write to a file and, in newer plugin versions, emit JSON, DOT, GraphML or TGF.

Cargo reflects a feature unified graph, which is close to what a build compiles but not an exact guarantee.

In Go, the build list is what minimal version selection chooses. With module graph pruning, some modules appear in the list but cannot be imported until you add them explicitly.

Steps

  1. Run the command for your ecosystem and save the output.
  2. Count how many packages are direct and how many are transitive.
  3. Run your vulnerability scan against the same project.
  4. For each transitive finding, trace the path to a direct parent. A companion post covers that step.

Why bother

The OWASP Top 10 entry on vulnerable and outdated components lists, among the signs you are at risk, not knowing the versions of all components, nested dependencies included. A tree listing is the quickest way to answer that for one project.

Try it yourself

Click through it at your own pace, or open it full screen.

Expand a direct dependency to see how many transitive packages sit beneath it.

Quick check

Why is my tree different from my teammate's?

Usually a missing or stale lockfile. Without one, each machine resolves versions on its own.

Do dev dependencies appear in the tree?

Yes, unless you omit them. Most tools let you filter by dependency type.

Safeguard builds this inventory automatically as part of SBOM and dependency scanning. A free scan shows the tree for a repository.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.