Gradle 失败:无法解决:删除 kotlintest 后的 io
Gradle fails: Failed to resolve: io after removing kotlintest
我创建了一个新的 Android 项目并在 Intrument 测试和单元测试中设置了 mockk:
androidTestImplementation "io.mockk:mockk:{1.9.3}"
testImplementation "io.mockk:mockk:{1.9.3}"
Gradle 同步正常。
如果我添加 kotlintest 并再次同步一切正常:
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.testing"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests.all {
useJUnitPlatform()
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//Mocking framework
androidTestImplementation "io.mockk:mockk:{1.9.3}"
testImplementation "io.mockk:mockk:{1.9.3}"
//Testing framework
androidTestImplementation 'io.kotlintest:kotlintest-runner-junit5:3.3.0'
testImplementation 'io.kotlintest:kotlintest-runner-junit5:3.3.0'
}
但是如果我删除 kotlintest 并像添加 kotlintest 之前一样保留 gradle 文件,那么我会收到错误消息:
Failed to resolve: io
这是我的最终 Gradle 文件:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.testing"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//Mocking framework
androidTestImplementation "io.mockk:mockk:{1.9.3}"
testImplementation "io.mockk:mockk:{1.9.3}"
}
我尝试清理项目并清理 gradle。
知道为什么会这样吗?
谢谢
您的 mockk
库版本包含 {}
。
我们通常在处理变量或 ext
块中的版本时使用它们:
testImplementation "io.mockk:mockk:${Version.mockkVersion}"
在你的情况下,当使用固定值时,你不应该使用大括号:
testImplementation "io.mockk:mockk:1.9.3"
它应该可以很好地与此更改同步
我创建了一个新的 Android 项目并在 Intrument 测试和单元测试中设置了 mockk:
androidTestImplementation "io.mockk:mockk:{1.9.3}"
testImplementation "io.mockk:mockk:{1.9.3}"
Gradle 同步正常。
如果我添加 kotlintest 并再次同步一切正常:
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.testing"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests.all {
useJUnitPlatform()
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//Mocking framework
androidTestImplementation "io.mockk:mockk:{1.9.3}"
testImplementation "io.mockk:mockk:{1.9.3}"
//Testing framework
androidTestImplementation 'io.kotlintest:kotlintest-runner-junit5:3.3.0'
testImplementation 'io.kotlintest:kotlintest-runner-junit5:3.3.0'
}
但是如果我删除 kotlintest 并像添加 kotlintest 之前一样保留 gradle 文件,那么我会收到错误消息:
Failed to resolve: io
这是我的最终 Gradle 文件:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.testing"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//Mocking framework
androidTestImplementation "io.mockk:mockk:{1.9.3}"
testImplementation "io.mockk:mockk:{1.9.3}"
}
我尝试清理项目并清理 gradle。
知道为什么会这样吗?
谢谢
您的 mockk
库版本包含 {}
。
我们通常在处理变量或 ext
块中的版本时使用它们:
testImplementation "io.mockk:mockk:${Version.mockkVersion}"
在你的情况下,当使用固定值时,你不应该使用大括号:
testImplementation "io.mockk:mockk:1.9.3"
它应该可以很好地与此更改同步