Visitar URL original
Kotlin example for adding Mockito as an agent is incorrect · Issue #3864 · mockito/mockito · GitHub
Skip to content

Kotlin example for adding Mockito as an agent is incorrect #3864

Closed

Description

@holler7

* <pre class="code"><code class="kotlin">
* val mockitoAgent = configurations.create("mockitoAgent")
* dependencies {
* testImplementation(libs.mockito)
* mockitoAgent(libs.mockito) { isTransitive = false }
* }
* tasks {
* test {
* jvmArgs.add("-javaagent:${mockitoAgent.asPath}")
* }
* }
* </code></pre>

When encountering the inline agent warning and subsequently navigating to the javadoc with build configuration example to add Mockito as an agent, the Kotlin example gives an example for adding the jvmArgs that is incorrect:

tasks { test { jvmArgs.add("-javaagent:${mockitoAgent.asPath}") }

This code won't actually add to jvmArgs as in this context jvmArgs is a getter for a copy, and the add command just adds to that copy and doesn't persist. The corrected code should be the following, which is a method call to add arguments:

tasks { test { jvmArgs("-javaagent:${mockitoAgent.asPath}") }

Activity

  1. jselbo commented on Sep 22, 2026

    @jselbo
    Collaborator

    Thanks, I put up a PR to fix the example here.

  2. added a commit that references this issue on Sep 23, 2026
    5a2f0f8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions