Skip to content

Fix UpgradeDependencyVersion not upgrading parent dependencyManagement after ChangeDependency in multi-module projects#8155

Draft
timtebeek wants to merge 1 commit into
mainfrom
tim/palembang
Draft

Fix UpgradeDependencyVersion not upgrading parent dependencyManagement after ChangeDependency in multi-module projects#8155
timtebeek wants to merge 1 commit into
mainfrom
tim/palembang

Conversation

@timtebeek

@timtebeek timtebeek commented Jun 30, 2026

Copy link
Copy Markdown
Member

What's changed

1. UpdateMavenModel discarded a parent's valid update when a child module failed to re-resolve

After ChangeDependency renames a managed dependency in the parent POM, maybeUpdateModel() re-resolves the parent — including, recursively, its aggregated child modules. The child still references the old (now unmanaged) coordinates, so it cannot resolve a version mid-recipe and throws MavenDownloadingExceptions. That exception caused the entire parent update to be thrown away, leaving the parent's resolved MavenResolutionResult stale. The subsequent UpgradeDependencyVersion then couldn't find the managed dependency and left the parent at the old version.

Module re-resolution is now best-effort: a module that can't be resolved keeps its previous resolution (it is refreshed when its own source file is updated later in the run) and no longer invalidates the parent POM's own valid update.

2. ChangeDependencyGroupIdAndArtifactId added an explicit version to provided/test dependencies managed by a local parent

The managed-dependency detection used Scope.isInClasspathOf, which models transitive classpath visibility and returns false for provided/provided and test/test. As a result, a provided child dependency managed by a provided entry in a local parent was treated as unmanaged, and an explicit <version> was added. Maven applies a managed version whenever coordinates match regardless of scope, so an identical scope now correctly counts as managed.

Testing

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Jun 30, 2026
@timtebeek timtebeek marked this pull request as draft June 30, 2026 18:01
…t after ChangeDependency in multi-module projects

Two distinct multi-module bugs caused the chained
`ChangeDependency` -> `UpgradeDependencyVersion` scenario from #8145 to fail:

1. `UpdateMavenModel` discarded a parent POM's own valid model update when
   re-resolving one of its aggregated child modules threw. After
   `ChangeDependency` renames a managed dependency in the parent, the child
   module still references the old (now unmanaged) coordinates and cannot be
   resolved mid-recipe. The resulting `MavenDownloadingExceptions` caused the
   entire parent update to be thrown away, leaving the parent's resolved model
   stale, so the following `UpgradeDependencyVersion` could not find the managed
   dependency to upgrade. Module re-resolution is now best-effort: a failing
   module keeps its previous resolution (it is refreshed when its own source
   file is updated) and no longer invalidates the parent's update.

2. `ChangeDependencyGroupIdAndArtifactId` added a spurious explicit `<version>`
   to a child dependency whose version is managed by a local parent when the
   dependency uses `provided` (or `test`) scope. The managed-dependency check
   used `Scope.isInClasspathOf`, which models transitive classpath visibility
   and returns `false` for `provided`/`provided` and `test`/`test`. Version
   management applies whenever coordinates match regardless of scope, so an
   identical scope now correctly counts as managed.
@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Jun 30, 2026
}

private boolean canAffectManagedDependency(MavenResolutionResult result, Scope scope, String groupId, String artifactId) {
// We're only going to be able to effect managed dependencies that are either direct or are brought in as direct via a local parent

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be the word affect rather than effect, but not worth fixing separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready to Review

Development

Successfully merging this pull request may close these issues.

UpgradeDependencyVersion does not update a <dependencyManagement> entry in a parent POM following ChangeDependency in the same run

2 participants