Skip to content

Commit 7fbd3ab

Browse files
authored
Use Mockito Java agent for mock instrumentation (#2275)
This change fixes the following warning during tests: Mockito is currently self-attaching to enable the inline-mock-maker. This will no longer work in future releases of the JDK. Please add Mockito as an agent to your build as described in Mockito's documentation: https://javadoc.io/doc/org.mockito/mockito-core/latest/org.mockito/org/mockito/Mockito.html#0.3 WARNING: A Java agent has been loaded dynamically (.../byte-buddy-agent-1.17.5.jar) WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information WARNING: Dynamic loading of agents will be disallowed by default in a future release
1 parent 0c790e0 commit 7fbd3ab

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

build-logic/src/main/kotlin/polaris-java.gradle.kts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ testing {
140140
}
141141
}
142142

143+
val mockitoAgent = configurations.create("mockitoAgent")
144+
143145
dependencies {
144146
val libs = versionCatalogs.named("libs")
145147
testFixturesImplementation(
@@ -155,18 +157,24 @@ dependencies {
155157
GradleException("assertj-core not declared in libs.versions.toml")
156158
}
157159
)
158-
testFixturesImplementation(
160+
val mockitoCoreLib =
159161
libs.findLibrary("mockito-core").orElseThrow {
160162
GradleException("mockito-core not declared in libs.versions.toml")
161163
}
162-
)
164+
165+
testFixturesImplementation(mockitoCoreLib)
166+
167+
mockitoAgent(mockitoCoreLib) { isTransitive = false }
163168
}
164169

165170
tasks.withType<Test>().configureEach {
166171
systemProperty("file.encoding", "UTF-8")
167172
systemProperty("user.language", "en")
168173
systemProperty("user.country", "US")
169174
systemProperty("user.variant", "")
175+
jvmArgumentProviders.add(
176+
CommandLineArgumentProvider { listOf("-javaagent:${mockitoAgent.asPath}") }
177+
)
170178
}
171179

172180
tasks.withType<Jar>().configureEach {

0 commit comments

Comments
 (0)