1

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
  • Each Gradle module is an independent build with its own dependencies and compilations etc. So naturally it is possible for each build to have a unique dependency configuration. Your question seems to be a bit more: "how can I modify my multimodule project with its code that applies the same configuration to different modules to apply a different configuration to one module?" If you want help with that question, you will need to share the code that does said centralised configuration and maybe people can suggest how to adapt it. Commented Dec 13, 2024 at 18:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.