Skip to content

Commit 2d168dc

Browse files
committed
build: add Mockito agent path to JVM arguments for test execution
1 parent 12fe52e commit 2d168dc

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

pom.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,24 @@
274274
<mavenExecutorId>forked-path</mavenExecutorId>
275275
</configuration>
276276
</plugin>
277+
<plugin><!-- Exposes the mockito-core jar path as ${org.mockito:mockito-core:jar}, so it can be loaded as a -javaagent (Mockito no longer self-attaches on recent JDKs). -->
278+
<groupId>org.apache.maven.plugins</groupId>
279+
<artifactId>maven-dependency-plugin</artifactId>
280+
<executions>
281+
<execution>
282+
<id>get-mockito-agent-path</id>
283+
<goals>
284+
<goal>properties</goal>
285+
</goals>
286+
</execution>
287+
</executions>
288+
</plugin>
277289
<plugin>
278290
<groupId>org.apache.maven.plugins</groupId>
279291
<artifactId>maven-surefire-plugin</artifactId>
280292
<version>${maven-surefire-plugin.version}</version>
281293
<configuration><!-- Sets the VM argument line used when unit tests are run. -->
282-
<argLine>${surefireArgLine} --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED --add-opens java.base/jdk.internal.reflect=ALL-UNNAMED -Dnet.bytebuddy.experimental=true --sun-misc-unsafe-memory-access=allow</argLine>
294+
<argLine>-javaagent:${org.mockito:mockito-core:jar} ${surefireArgLine} --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED --add-opens java.base/jdk.internal.reflect=ALL-UNNAMED -Dnet.bytebuddy.experimental=true --sun-misc-unsafe-memory-access=allow</argLine>
283295
</configuration>
284296
</plugin>
285297
<plugin>
@@ -293,7 +305,7 @@
293305
<goal>verify</goal>
294306
</goals>
295307
<configuration>
296-
<argLine>${failsafeArgLine} --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED --add-opens java.base/jdk.internal.reflect=ALL-UNNAMED -Dnet.bytebuddy.experimental=true --sun-misc-unsafe-memory-access=allow</argLine>
308+
<argLine>-javaagent:${org.mockito:mockito-core:jar} ${failsafeArgLine} --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED --add-opens java.base/jdk.internal.reflect=ALL-UNNAMED -Dnet.bytebuddy.experimental=true --sun-misc-unsafe-memory-access=allow</argLine>
297309
</configuration>
298310
</execution>
299311
</executions>

0 commit comments

Comments
 (0)