Skip to content

Raise a Mockito version property in a parent pom when UpgradeToJava25 migrates mockito-all - #1453

Open
ds-xdev wants to merge 1 commit into
mainfrom
ds/mockito-all-version-property-for-java25
Open

ds-xdev wants to merge 1 commit into
mainfrom
ds/mockito-all-version-property-for-java25

Conversation

@ds-xdev

@ds-xdev ds-xdev commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Problem

UpgradeToJava25 (through UpgradeMockito1ForJava25) changes mockito-all to mockito-core and migrates the test code to Mockito 5. When the version comes from a property defined in a parent pom, as is common in multi-module builds, that property stays on 1.x. The module then depends on mockito-core 1.x while its tests use Mockito 5 APIs, so test compilation fails, e.g. with package org.mockito.junit does not exist.

Before

<!-- parent -->
<properties>
    <version.mockito>1.10.19</version.mockito>
</properties>

<!-- child -->
<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-all</artifactId>
    <version>${version.mockito}</version>
    <scope>test</scope>
</dependency>

After (Problem)

<!-- parent: still Mockito 1, while the tests were migrated to Mockito 5 -->
<properties>
    <version.mockito>1.10.19</version.mockito>
</properties>

<!-- child -->
<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-core</artifactId>
    <version>${version.mockito}</version>
    <scope>test</scope>
</dependency>

After (Expected)

<!-- parent -->
<properties>
    <version.mockito>5.20.0</version.mockito>
</properties>

Cause

All scanners of the composite run on the original sources. The Mockito UpgradeDependencyVersion steps therefore still see mockito-all, which has no 3.x, 4.x or 5.x release, and never record the property in the parent pom; in the edit phase they only update properties defined in the same pom. The step cannot go into UpgradeMockito1ForJava25 either, as its ModuleHasDependency precondition excludes a parent module that declares no Mockito dependency itself.

Fix

Add a ChangeDependency from mockito-all to mockito-core with newVersion: 5.20.x to UpgradePluginsForJava25, right after UpgradeMockito1ForJava25. Its scanner records a version property defined in a parent pom in the project and raises it to the 5.20.x that the following UpgradeDependencyVersion targets. Updated recipes.csv, and added raiseMockitoAllVersionPropertyInParent to UpgradeLegacyMockitoForJava25Test, which fails without the change. An existing Gradle mockito-core version variable above 5.20 is not downgraded.

…5` migrates `mockito-all`

The Mockito version upgrade scans the project before `mockito-all` is changed to
`mockito-core`, and `mockito-all` has no 5.x, so a version property defined in a
parent pom stayed on 1.x while the tests were migrated to Mockito 5 and no longer
compiled. A `ChangeDependency` with a `newVersion` raises that property. It runs
outside `UpgradeMockito1ForJava25`, whose precondition excludes a parent module
that does not declare Mockito itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant