Conflict with dependency [1.x] - mockito/mockito-kotlin GitHub Wiki

Note: this issue only occurs with version 1.x of Mockito-Kotlin.

Error:Conflict with dependency 'org.jetbrains.kotlin:kotlin-stdlib' in project ':app'. Resolved versions for app (x.x.x) and test app (y.y.y) differ.

Mockito-Kotlin depends on both org.jetbrains.kotlin:kotlin-stdlib:1.0.7 and org.jetbrains.kotlin:kotlin-reflect:1.0.7. By adding Mockito-Kotlin to your test configuration, you automatically depend on kotlin-reflect:1.0.7. This may cause issues if your app depends on a newer version of the standard library of Kotlin, e.g. kotlin-stdlib:1.1.50.

To solve this problem, you'll need to explicitly depend on the newer version of kotlin-reflect yourself. This ensures that the older kotlin-reflect library gets replaced by the newer version.

For Gradle users:

dependencies {
  compile 'org.jetbrains.kotlin:kotlin-stdlib:1.1.50'
  
  testCompile 'com.nhaarman:mockito-kotlin:x.x.x' // Pulls in kotlin-reflect:1.0.7
  testCompile 'org.jetbrains.kotlin:kotlin-reflect:1.1.50'
}

You can also use a resolution strategy:

subprojects {
    configurations.all {
        resolutionStrategy {
            forcedModules = [
              "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion",
              "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
             ]
        }
    }
}

This ensures all your kotlin dependencies will be resolved to $kotlinVersion.

Multiple artifacts

As a test, Mockito-Kotlin produced a mockito-kotlin-kt1.1 artifact as well to overcome this issue. Since this solution doesn't scale, it has been abandoned. Use one of the solutions above instead.

Notes

An issue is open on the Kotlin tracker that investigates this problem.