Exclude a transitive mockito-all from modules that move off PowerMock
org.openrewrite.java.testing.mockito.ExcludeMockitoAllReplacingPowerMockArtifactorg.openrewrite.recipe:rewrite-testing-frameworksExcludes mockito-all from the dependencies that bring it into a module that depends on the PowerMock Mockito API. mockito-all is a 1.x-only uber jar with its own org.mockito.Mockito, which shadows the one of the Mockito 3.x that replaces PowerMock wherever it comes first on the classpath, so that Mockito.mockStatic and MockedStatic do not resolve. The Hamcrest 1.1 and Objenesis classes bundled in mockito-all go with it. Only the Maven dependencies declared in the module itself are excluded from, not those it inherits from a parent that does not depend on PowerMock. Where UpgradeMockitoCoreReplacingPowerMock runs again in a later cycle, it pairs the exclusion with one of mockito-core, which is harmless as the module declares the Mockito that replaces PowerMock.
Add to your build
~/.gradle/gradle.properties
codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN
build.gradle.kts
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.java.testing.mockito.ExcludeMockitoAllReplacingPowerMock")
}
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-testing-frameworks:3.49.0")
}
Then run
./gradlew rewriteRunUsage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.java.testing.mockito.ExcludeMockitoAllReplacingPowerMockIf the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite.recipe:rewrite-testing-frameworks:RELEASEDefinition
This recipe runs the following recipes in order.
- Exclude Maven dependency
org.mockito:mockito-allorg.openrewrite.maven.ExcludeDependency
Data tables
Structured output this recipe can produce.
- Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats