Skip to content

Add direct mockwebserver3 dep when only inherited from parent pom#1011

Merged
steve-aom-elliott merged 2 commits into
mainfrom
upgrade-okhttp-mockwebserver-add-direct-dep
Jun 2, 2026
Merged

Add direct mockwebserver3 dep when only inherited from parent pom#1011
steve-aom-elliott merged 2 commits into
mainfrom
upgrade-okhttp-mockwebserver-add-direct-dep

Conversation

@steve-aom-elliott
Copy link
Copy Markdown
Contributor

What

Adds an AddDependency step to the UpgradeOkHttpMockWebServer recipe so that com.squareup.okhttp3:mockwebserver3:5.x (test scope) is written into the project's own pom when the old mockwebserver artifact came in via an inherited <dependencies> block from a parent pom.

Why

ChangeDependency only operates on dependencies declared directly in the pom under refactor. When the dep was declared in a parent pom that's outside the refactor scope (a corporate parent, an external BOM, etc.), ChangeDependency has nothing to rewrite, and the project is left without any declared mockwebserver3 dependency despite still using okhttp3.mockwebserver.* types in source.

Adding AddDependency with onlyIfUsing: okhttp3.mockwebserver..* and acceptTransitive: true covers this case: if the new artifact isn't already on the classpath as direct or transitive, it's added directly to the consumer's pom.

Test

Added shouldAddDirectDependencyWhenInheritedFromExternalParent to UpgradeOkHttpMockWebServerTest. The child pom in the fixture declares <parent>com.huawei.openstack4j.connectors:openstack4j-connectors:1.0.26</parent> — a real Maven Central pom-packaged artifact that declares mockwebserver:3.2.0 (test scope) in its <dependencies> block. Since the parent isn't part of the test fixture's project, the recipe cannot modify it, mirroring the customer scenario.

The test asserts:

  • The child pom gains a direct <dependency> on mockwebserver3 at 5.x with <scope>test</scope>.
  • Java source import okhttp3.mockwebserver.MockWebServer is rewritten to import mockwebserver3.MockWebServer (via the existing UpdateMockWebServerMockResponseChangePackage step).

Marking draft because I haven't been able to run the affected tests locally due to a SNAPSHOT-drift issue in my workspace that breaks every test in this module that parses Java (a known-good sibling test fails identically). CI will be the first clean signal.

Adds an `AddDependency` step to `UpgradeOkHttpMockWebServer` so the
recipe writes `com.squareup.okhttp3:mockwebserver3:5.x` (test scope)
into the project's own pom when the old `mockwebserver` artifact was
only available via a parent pom's inherited `<dependencies>`. Without
this, `ChangeDependency` is a no-op for inherited deps and consumers
end up with no direct declaration of the new artifact.

The new test uses `com.huawei.openstack4j.connectors:openstack4j-connectors:1.0.26`
(a real Maven Central pom-packaged artifact) as an external parent
so the recipe cannot modify the parent — mirroring the customer's
scenario where the parent pom is out of their refactoring scope.
The previous parent (com.huawei.openstack4j.connectors:openstack4j-connectors:1.0.26)
inherited a `${project.version}` dependency, which Maven resolves
against the child pom's version — causing CI to try to fetch a
nonexistent com.huawei:openstack4j-core:0.0.1-SNAPSHOT.

com.github.scribejava:scribejava:8.3.3 is pom-packaged, declares
mockwebserver:4.10.0 (test scope) in <dependencies> with an explicit
version, and has no `${project.version}` references anywhere.
@steve-aom-elliott steve-aom-elliott marked this pull request as ready for review June 2, 2026 15:50
@steve-aom-elliott steve-aom-elliott added enhancement New feature or request recipe Recipe request test provided labels Jun 2, 2026
@steve-aom-elliott steve-aom-elliott moved this from In Progress to Ready to Review in OpenRewrite Jun 2, 2026
@steve-aom-elliott steve-aom-elliott merged commit 9479988 into main Jun 2, 2026
1 check passed
@steve-aom-elliott steve-aom-elliott deleted the upgrade-okhttp-mockwebserver-add-direct-dep branch June 2, 2026 15:52
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Jun 2, 2026
mergify Bot added a commit to robfrank/linklift that referenced this pull request Jun 4, 2026
…rom 3.35.2 to 3.37.0 [skip ci]

Bumps [org.openrewrite.recipe:rewrite-testing-frameworks](https://github.com/openrewrite/rewrite-testing-frameworks) from 3.35.2 to 3.37.0.
Release notes

*Sourced from [org.openrewrite.recipe:rewrite-testing-frameworks's releases](https://github.com/openrewrite/rewrite-testing-frameworks/releases).*

> 3.37.0
> ------
>
> What's Changed
> --------------
>
> * Reuse `MockedStatic` for consecutive stubbings of the same class by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#1005](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1005)
> * Add RemoveJupiterMigrationSupport recipe by [`@​sullis`](https://github.com/sullis) in [openrewrite/rewrite-testing-frameworks#1006](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1006)
> * Regenerate recipes.csv by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#1007](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1007)
> * fix: retain doNothing() stubs inside lambda bodies to prevent uncompilable code by [`@​darrencilia`](https://github.com/darrencilia) in [openrewrite/rewrite-testing-frameworks#1009](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1009)
> * Migrate deprecated AssertionsForClassTypes/InterfaceTypes to Assertions by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#1010](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1010)
> * Add direct mockwebserver3 dep when only inherited from parent pom by [`@​steve-aom-elliott`](https://github.com/steve-aom-elliott) in [openrewrite/rewrite-testing-frameworks#1011](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1011)
> * Match MockWebServer.shutdown() against pre-rename type by [`@​steve-aom-elliott`](https://github.com/steve-aom-elliott) in [openrewrite/rewrite-testing-frameworks#1012](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1012)
>
> New Contributors
> ----------------
>
> * [`@​darrencilia`](https://github.com/darrencilia) made their first contribution in [openrewrite/rewrite-testing-frameworks#1009](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1009)
>
> **Full Changelog**: <openrewrite/rewrite-testing-frameworks@v3.36.0...v3.37.0>
>
> 3.36.0
> ------
>
> What's Changed
> --------------
>
> * Skip wrapper-primitive in `UseAssertSame`; rewrite via `AssertTrueComparisonToAssertEquals` by [`@​motlin`](https://github.com/motlin) in [openrewrite/rewrite-testing-frameworks#995](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/995)
> * Add unit test for JUnit6BestPractices by [`@​sullis`](https://github.com/sullis) in [openrewrite/rewrite-testing-frameworks#994](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/994)
> * Cleanup junit vintage engine by [`@​sullis`](https://github.com/sullis) in [openrewrite/rewrite-testing-frameworks#993](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/993)
> * OpenRewrite recipe best practices by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#997](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/997)
> * Fix `JUnit4to5Migration` for classes that extend `org.junit.Assert` by [`@​motlin`](https://github.com/motlin) in [openrewrite/rewrite-testing-frameworks#996](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/996)
> * Preserve newlines when converting `@CsvSource(textBlock = ...)` to `@ValueSource` by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#998](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/998)
> * Fix `EnclosedToNested` failing with "Expected to find enclosing JavaSourceFile" by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#1001](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1001)
> * Fix `assertEquals` delta misinterpreted as message in AssertJ conversion by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#1000](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1000)
> * Add JUnit 6.1 migration recipes by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#1002](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1002)
> * Handle Kotlin sources in `MockitoWhenOnStaticToMockStatic` by [`@​MBoegers`](https://github.com/MBoegers) in [openrewrite/rewrite-testing-frameworks#1003](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1003)
>
> **Full Changelog**: <openrewrite/rewrite-testing-frameworks@v3.35.3...v3.36.0>
>
> v3.35.3
> -------
>
> What's Changed
> --------------
>
> * OpenRewrite [v8.81.6](https://github.com/openrewrite/rewrite/releases/tag/v8.81.6)
> * Cleanup Mockito AutoCloseable fields by [`@​sullis`](https://github.com/sullis) in [openrewrite/rewrite-testing-frameworks#977](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/977)
> * Preserve mockStatic when returned from helper methods by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#979](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/979)
> * Upgrade junit-bom to 6.x in JUnit 5 to 6 migration by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#978](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/978)
> * Tighten PowerMockitoMockStaticToMockito precondition to actual PowerMockito usage by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#981](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/981)
> * Fix AssertTrueInstanceofToAssertInstanceOf static import by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#984](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/984)
> * Fix `ClassCastException` for `@PrepareForTest(fullyQualifiedNames = "...")` by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#983](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/983)
> * Preserve `doNothing()` stubbings using `ArgumentCaptor.capture()` by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#988](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/988)
> * Document strictness implication of `RemoveInitMocksIfRunnersSpecified` by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#990](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/990)
> * Support `textBlock` attribute in `CsvSourceToValueSource` by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#989](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/989)
> * Skip primitive comparisons in `UseAssertSame` by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#992](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/992)
>
> **Full Changelog**: <openrewrite/rewrite-testing-frameworks@v3.35.2...v3.35.3>


Commits

* [`5b719c2`](openrewrite/rewrite-testing-frameworks@5b719c2) Extract documentation examples from tests
* [`1ca6223`](openrewrite/rewrite-testing-frameworks@1ca6223) Match MockWebServer.shutdown() against pre-rename type ([#1012](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1012))
* [`9479988`](openrewrite/rewrite-testing-frameworks@9479988) Add direct mockwebserver3 dep when only old mockwebserver dep inherited from ...
* [`4d31fbb`](openrewrite/rewrite-testing-frameworks@4d31fbb) Add recipe to migrate AssertionsForClassTypes/InterfaceTypes to Assertions (#...
* [`7cbff2a`](openrewrite/rewrite-testing-frameworks@7cbff2a) OpenRewrite recipe best practices
* [`86f2308`](openrewrite/rewrite-testing-frameworks@86f2308) fix: retain doNothing() stubs inside lambda bodies to prevent uncompilable co...
* [`45d2528`](openrewrite/rewrite-testing-frameworks@45d2528) Update Gradle wrapper 9.5.1
* [`a632e17`](openrewrite/rewrite-testing-frameworks@a632e17) Regenerate recipes.csv ([#1007](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1007))
* [`0b192ca`](openrewrite/rewrite-testing-frameworks@0b192ca) Add RemoveJupiterMigrationSupport recipe ([#1006](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1006))
* [`f3f61a6`](openrewrite/rewrite-testing-frameworks@f3f61a6) Reuse `MockedStatic` for consecutive stubbings of the same class ([#1005](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1005))
* Additional commits viewable in [compare view](openrewrite/rewrite-testing-frameworks@v3.35.2...v3.37.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request recipe Recipe request test provided

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant