Skip to content

Install Mockito as a JVM -javaagent on every Test task#4349

Open
ScottDugas wants to merge 1 commit into
FoundationDB:mainfrom
ScottDugas:subissue-4334
Open

Install Mockito as a JVM -javaagent on every Test task#4349
ScottDugas wants to merge 1 commit into
FoundationDB:mainfrom
ScottDugas:subissue-4334

Conversation

@ScottDugas

@ScottDugas ScottDugas commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Mockito's inline mock maker can no longer self-attach to a running JVM on JDK 21+, which (a) emits a warning that is scheduled to become an error and (b) races under parallel JUnit class execution, manifesting as IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker.

Following Mockito's own JDK 21+ recommendation, declare a resolvable mockitoAgent configuration that resolves to the mockito-core jar and attach it via -javaagent to every Test JVM. The -javaagent flag is added inside a doFirst block so the mockitoAgent configuration is not resolved during evaluation, which would prevent the root build's resolutionStrategy.eachDependency callback from attaching to it.

Closes #4334

Mockito's inline mock maker can no longer self-attach to a running JVM
on JDK 21+, which (a) emits a warning that is scheduled to become an
error and (b) races under parallel JUnit class execution, manifesting
as IllegalStateException: Could not initialize plugin: interface
org.mockito.plugins.MockMaker.

Following Mockito's own JDK 21+ recommendation, declare a resolvable
mockitoAgent configuration that resolves to the mockito-core jar and
attach it via -javaagent to every Test JVM. The -javaagent flag is
added inside a doFirst block so the mockitoAgent configuration is not
resolved during evaluation, which would prevent the root build's
resolutionStrategy.eachDependency callback from attaching to it.

Closes FoundationDB#4334
@ScottDugas ScottDugas added the build improvement Improvement to the build system label Jul 13, 2026
@ScottDugas ScottDugas requested a review from RobertBrunel July 13, 2026 20:28
@ScottDugas ScottDugas marked this pull request as ready for review July 13, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build improvement Improvement to the build system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Install Mockito as a JVM -javaagent on every Test task

1 participant