I have migrated our multi-module Gradle project from Mockito v1 to Mockito v3. As part of the migration, the following libraries were upgraded or added:
mockito-core from 1.10.19 to 3.12.4 (and added mockito-inline 3.12.4)
powermock-api-mockito from 1.6.6 to powermock-api-mockito2 2.0.9
powermock-api-support to 2.0.9
Also added bytebuddy support:
byte-buddy 1.11.13
byte-buddy-agent 1.11.13
I’ve fixed a large number of tests (almost 500 files) for now, but after further investigation, I found one class causing issues. The tests pass only if we include support for mockito-inline (there are some final classes that we mock from a third-party library). However, the tests in the other modules only pass if they depend on mockito-core.
Is it possible to exclude specific dependencies for each module in Gradle while keeping mockito-core defined in the root build.gradle
Tried to
testImplementation("org.mockito:mockito-inline:3.12.4") {
exclude group: 'org.mockito', module: 'mockito-core'
}
That approach still includes the dependency in the module, which isn’t ideal. I’d like to exclude the unnecessary Mockito dependencies for specific modules so we can move forward for now. Later, we can revisit this to improve the setup, as rewriting a large number of tests to make everything compatible is time-consuming.
Currently, in the root build.gradle, I’m also forcing the Mockito version to avoid conflicts with PowerMock:
// Force 'org.mockito:mockito-core:3.12.4' to avoid conflicts with Powermock's Mockito 3.3.3
force libraries.mockito_core
force libraries.mockito_inline
Is there a way to figure it out?
1