[英]Cannot resolve Mockito dependency in Gradle
雖然我看到兩個不同的帖子帶有此錯誤消息,但對我沒有任何作用:
錯誤:(25, 17) 無法解決:org.mockito:mockito-core:1.10.19
我嘗試使用 compile、androidTestCompile 和 testCompile 更改 Mockito 依賴項,並且在全局 Gradle 文件中我嘗試將 Maven 添加為存儲庫,但沒有成功。
編輯:我使用的是 Android Studio 2.1
這是我的應用程序 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'
}
這是全球的
// 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
}
我找到了解決方案。 在大部分教程中都是為了添加mockito-core而編寫的。 而是添加 mockito-all 解決了我的問題,使 gradle 編譯沒有錯誤
如果您想在 JUnit 5 中使用 Mockito,mockito-all 將沒有任何用處。 相反,請確保將 mavenCentral 添加到全局 gradle 文件中的存儲庫列表中。
像:
buildscript {
repositories {
jcenter()
mavenCentral()
}
...
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.