Skip to content

Mark parent tag in DependencyInsight when dependency is inherited#6693

Merged
sambsnyd merged 5 commits intomainfrom
dep-insight-mark-parent
Feb 6, 2026
Merged

Mark parent tag in DependencyInsight when dependency is inherited#6693
sambsnyd merged 5 commits intomainfrom
dep-insight-mark-parent

Conversation

@Jenson3210
Copy link
Copy Markdown
Contributor

@Jenson3210 Jenson3210 commented Feb 6, 2026

Summary

  • Extended DependencyInsight to mark the <parent> tag when matching dependencies are inherited from parent POMs
  • Added logic to correctly handle cases where a target dependency is reachable through multiple paths
  • Only marks parent for targets that aren't covered by any declared dependency in the current POM

Problem

When Spring dependencies are declared in an external parent POM (not part of the project being analyzed), DependencyInsight couldn't find them because it only marked <dependency> tags. When there's no <dependency> tag in the child POM for a dependency inherited from the parent, nothing got marked, and preconditions like IsLikelySpringFramework failed.

This caused the SpringToSpringBoot recipe to skip processing when Spring dependencies came solely from parent inheritance.

Solution

Modified DependencyInsight.MarkIndividualDependency to also check and mark <parent> tags:

  1. When visiting a <parent> tag, collect all target dependencies that are NOT reachable through any declared <dependency> in the current POM
  2. Mark the parent tag with those inherited-only targets
  3. Handle the case where a target is reachable through multiple paths (e.g., spring-core via both spring-boot-starter-web and spring-web) - if ANY path goes through a declared dependency, don't mark the parent for that target

Test plan

  • Existing tests pass

  • Added findDependencyDeclaredInProjectParent - parent declares dependency, child inherits → child's <parent> tag is marked

  • Added doNotMarkParentTagWhenDependencyDeclaredInChild - child declares the target directly → only <dependency> tag is marked

  • Added doNotMarkParentTagWhenTransitiveDependencyComesFromChildDeclaredDependency - child declares dependency that transitively brings target → only <dependency> tag is marked

  • Fixes moderneinc/customer-requests#1803

When a dependency is inherited from an external parent POM,
the <parent> tag should be marked by DependencyInsight.
Currently only <dependency> tags are marked.

Reproducer for moderneinc/customer-requests#1803
When a dependency is inherited from a parent POM (rather than declared
directly in the current POM), DependencyInsight now marks the <parent>
tag with the matching dependencies. This fixes the issue where
preconditions like IsLikelySpringFramework would fail when Spring
dependencies were only present through parent inheritance.

Fixes moderneinc/customer-requests#1803
Verifies that when a child POM declares its own dependency (even with
version from parent's dependencyManagement), only the <dependency> tag
is marked, not the <parent> tag.
A target dependency might be reachable through multiple "direct"
dependencies in Maven's resolution (e.g., spring-core via both
spring-boot-starter-web and spring-web). The parent tag should only
be marked if the target is NOT reachable through any declared
dependency.

Changed the algorithm to:
1. Collect all targets and track which are "covered" by declared deps
2. Only mark parent with targets that aren't covered

Added test for transitive dependency coming from child's declared
dependency.
@Jenson3210
Copy link
Copy Markdown
Contributor Author

verified on my reference project that this now marks the parent tag -> change will be detected.

@Jenson3210 Jenson3210 requested a review from sambsnyd February 6, 2026 23:54
@sambsnyd sambsnyd merged commit 9fe1fb5 into main Feb 6, 2026
2 checks passed
@sambsnyd sambsnyd deleted the dep-insight-mark-parent branch February 6, 2026 23:55
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants