Skip to content

Fixes Mockito getting PowerMock's version from parent pom properties and Gradle version variables - #1198

Merged
sambsnyd merged 3 commits into
mainfrom
powermock-dependency-version-scan
Oct 19, 2026
Merged

sambsnyd merged 3 commits into
mainfrom
powermock-dependency-version-scan

Conversation

@sambsnyd

Copy link
Copy Markdown
Member

ReplacePowerMockDependencies called ChangeDependency.getVisitor(), which gives the delegate an empty accumulator because its scanner never runs. As a result, a PowerMock version held in a parent pom property or a Gradle version variable was never updated. The dependency was renamed to org.mockito:mockito-core:${powermock.version}, which resolves to a Mockito version that doesn't exist, such as 2.0.9.

The recipe now:

  • holds the ChangeDependency delegates as fields and keeps their accumulators in its own Accumulator
  • runs every delegate's scanner during its own scan
  • visits each project with the delegate for that project's target, passing that delegate's accumulator

Tests cover a version property inherited from a parent pom and a version variable from gradle.properties. rewrite-properties is added as a test dependency for the second one.

Comment on lines +62 to +68
for (String powerMockArtifact : Arrays.asList("powermock-api-mockito", "powermock-api-mockito2")) {
for (String mockitoArtifact : Arrays.asList("mockito-core", "mockito-inline")) {
for (Boolean changeManagedDependency : Arrays.asList(null, false)) {
changeDependencies.add(new ChangeDependency(
"org.powermock", powerMockArtifact,
"org.mockito", mockitoArtifact, "3.x",
null, null, changeManagedDependency));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure I fully follow this triple nested for loop, also considering we only seem to test one combination, but if you're confident feel free to merge.

I've rebased to fix the CI failure that might have held you back.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good call, innermost loop was not needed, can just set true always

@sambsnyd
sambsnyd merged commit 6b5cb84 into main Oct 19, 2026
2 checks passed
@sambsnyd
sambsnyd deleted the powermock-dependency-version-scan branch October 19, 2026 19:53
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Oct 19, 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