Skip to content

[MDEP-927] Make dependency:tree excludes prune subtrees - #1671

Open
wilx wants to merge 1 commit into
apache:masterfrom
wilx:issue-1427-tree-excludes-subtrees
Open

[MDEP-927] Make dependency:tree excludes prune subtrees#1671
wilx wants to merge 1 commit into
apache:masterfrom
wilx:issue-1427-tree-excludes-subtrees

Conversation

@wilx

@wilx wilx commented Aug 2, 2026

Copy link
Copy Markdown

Summary

  • make dependency:tree prune a dependency matching excludes together with its complete subtree
  • apply exclusions before includes, so an include cannot restore a node beneath an excluded subtree
  • retain ancestor paths for included nodes that remain after exclusion pruning
  • document the behavior and add unit and integration coverage for pruning, sibling traversal, and combined filters

Root cause

The existing implementation combined includes and excludes into one node filter and applied it through FilteringDependencyNodeVisitor. A rejected node was omitted from the serialized output, but its children were still traversed. When includes were also present, the ancestor-or-self pass could restore paths through nodes that had matched an exclude pattern.

This change introduces a pruning visitor. A rejected node returns false from visit, preventing traversal of its children, while its matching endVisit returns true so traversal continues with the node's next sibling. The visitor remembers the acceptance decision made at the start of the visit so the delegate receives balanced visit/endVisit callbacks without evaluating the filter twice.

Semantics and compatibility

This intentionally changes the output-filtering semantics of dependency:tree:

  • excludes is a structural pruning operation. A matching node and every node below it are absent from the serialized tree.
  • includes is a positive filter over the tree that remains after pruning. It selects matching dependencies and retains the ancestor paths needed to reach them.
  • exclusions take precedence; includes cannot override them.
  • this affects only serialization of the dependency tree and does not change dependency collection or resolution.

As discussed in #1334, the current parameter names do not describe these distinct roles especially well. Names such as filter for the path-preserving positive selection and exclusions for subtree pruning would communicate the behavior more clearly. This PR retains the established includes and excludes names for CLI and plugin-configuration compatibility. Introducing aliases, deprecating the existing names, or renaming them should be considered separately as an API migration.

Validation

  • mvn spotless:apply
  • Maven 3: mvn verify — 412 tests passed, 1 skipped
  • Maven 3: mvn -Prun-its verify — 99 integration-test projects passed
  • Maven 4: mvn verify — 412 tests passed, 1 skipped
  • Maven 4: mvn -Prun-its verify — 98 integration-test projects passed, 1 skipped due to its Maven-version condition
  • Spring Web Services 4.0.11 reproducer with the snapshot plugin, both normal and -Dverbose=true: excluding org.glassfish.jaxb:jaxb-runtime also removes jaxb-core, txw2, and istack-commons-runtime

Fixes #1427

Fixes #1334

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@wilx
wilx marked this pull request as ready for review August 2, 2026 20:28
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.

[MDEP-927] dependency:tree excludes parameter does not work [MDEP-829] excludes filter should function like exclusions

1 participant