Gradle fails: Failed to resolve: io after removing kotlintest

本秂侑毒 提交于 2019-12-11 15:26:54

问题


I've created a new Android Project and set up mockk in Intrument test and Unit test:

    androidTestImplementation "io.mockk:mockk:{1.9.3}"
    testImplementation "io.mockk:mockk:{1.9.3}"

Gradle sync fine.

If I add kotlintest and sync again everything works:

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'
}

But if I remove kotlintest and I leave the gradle file as before adding kotlintest, then I get the error:

Failed to resolve: io

This is my final Gradle file:

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}"
}

I tried cleaning the project and cleaning gradle.

Any idea why this is happening?

Thanks


回答1:


Your version for the mockk library contains {}.

We usually use them when working with a version that is in a variable or in the ext block:

testImplementation "io.mockk:mockk:${Version.mockkVersion}"

In your case, when working with a fixed value, you shouldn't use the braces:

testImplementation "io.mockk:mockk:1.9.3"

It should sync fine with this change



来源:https://stackoverflow.com/questions/57325617/gradle-fails-failed-to-resolve-io-after-removing-kotlintest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!