1

Although I saw two different posts with this error message nothing worked with me:

Error:(25, 17) Failed to resolve: org.mockito:mockito-core:1.10.19

I tried to change the Mockito dependency using compile, androidTestCompile and testCompile and in the global Gradle file I tried to add Maven as repository but did not work.

EDIT: I am using Android Studio 2.1

This is my app build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.0"

defaultConfig {
    applicationId "ivano.android.com.mockitoexample"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'

}

and this the global one

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
lance-java
  • 25,497
  • 4
  • 59
  • 101
trocchietto
  • 2,607
  • 2
  • 23
  • 36

2 Answers2

6

I found the solution. In most of the tutorials is written to add mockito-core. Instead adding mockito-all fixed my problem, making gradle compiling without mistakes

trocchietto
  • 2,607
  • 2
  • 23
  • 36
0

In case you want to use Mockito with JUnit 5, mockito-all won't be of any use. Instead make sure to add mavenCentral to your list of repositories in the global gradle file.
Like:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }

    ...
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}
Moritz
  • 1,186
  • 1
  • 8
  • 7
  • 1
    Would be good to put `mavenCentral()` above `jcenter()`, as jcenter is at end of life (check this answer https://stackoverflow.com/a/67296946/2286422) – Myroslav Jun 04 '21 at 19:50