Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate class org.junit.platform.commons.annotation.Testable found in modules junit-platform-commons-1.4.0.jar (org.junit.platform:junit-platform-commons:1.4.0) and kotlintest-core-3.3.0.jar (io.kotlintest:kotlintest-core:3.3.0) #927

Closed
cepages opened this issue Jul 26, 2019 · 13 comments

Comments

@cepages
Copy link

commented Jul 26, 2019

Hi I'm new in Android and I'm trying to run some test.

But when I try to use kotlintest I get the following error:

Duplicate class org.junit.platform.commons.annotation.Testable found in modules junit-platform-commons-1.4.0.jar (org.junit.platform:junit-platform-commons:1.4.0) and kotlintest-core-3.3.0.jar (io.kotlintest:kotlintest-core:3.3.0)

This is my dependencies in gradle:

def grpcVersion = '1.22.1' // CURRENT_GRPC_VERSION
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:preference-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'org.nield:kotlin-statistics:1.1.3'
    implementation 'org.tensorflow:tensorflow-android:+'
    implementation 'com.android.support:multidex:1.0.3'

    implementation "org.jetbrains.anko:anko-commons:0.10.8"

    compileOnly "javax.annotation:jsr250-api:1.0"//This fixes the problem with Generated symbols

    // You need to build grpc-java to obtain these libraries below.
    implementation "io.grpc:grpc-okhttp:${grpcVersion}" // CURRENT_GRPC_VERSION
    implementation "io.grpc:grpc-protobuf-lite:${grpcVersion}" // CURRENT_GRPC_VERSION
    implementation "io.grpc:grpc-stub:${grpcVersion}" // CURRENT_GRPC_VERSION
    implementation 'com.google.code.gson:gson:2.8.5'

    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

    //Testing framework
    androidTestImplementation 'io.kotlintest:kotlintest-runner-junit5:3.3.0'

    //Mocking framework
    androidTestImplementation "io.mockk:mockk:1.9.3"
}

Thanks

@Kerooker Kerooker added the question label Jul 31, 2019

@Kerooker

This comment has been minimized.

Copy link
Member

commented Jul 31, 2019

This seems to be a problem in which 2 libraries are loading the same dependency.
Espresso is probably also bringing junit in, and their versions must be mismatching.

If you comment out espresso, does it work again? If it does, you'll have to exclude JUnit from one of the dependencies through an exclude block

@cepages

This comment has been minimized.

Copy link
Author

commented Aug 5, 2019

Removing Espresso didn't work. But I think I found where the dependency is. This is part of what I get when I run the dependency tree in gradle:

....

debugAndroidTestCompileClasspath - Compile classpath for compilation 'debugAndroidTest' (target  (androidJvm)).
+--- android.arch.core:core-testing:1.1.1
|    +--- junit:junit:4.12
|    |    \--- org.hamcrest:hamcrest-core:1.3
|    +--- org.mockito:mockito-core:2.7.6
|    +--- android.arch.core:runtime:1.1.1
|    |    +--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|    |    \--- android.arch.core:common:1.1.1
|    |         \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|    \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
+--- io.kotlintest:kotlintest-runner-junit5:3.3.0

....

I think android.arch.core:core-testing:1.1.1 is importing jUnit too.

I tried to exclude it with:

    androidTestImplementation 'android.arch.core:core-testing:1.1.1' {
        exclude module: "jUnit"
    }

But it seems doesn't work. I'm doing something wrong with gradle or I'm following the wrong clue

@Kerooker

This comment has been minimized.

Copy link
Member

commented Aug 6, 2019

Sometimes gradle just doesn't collaborate with Android.
Sometmes clearing the whoe gradle cache helps in these kinds of issues, specially with android

@Kerooker

This comment has been minimized.

Copy link
Member

commented Aug 6, 2019

Could you try that and report back?

@cepages

This comment has been minimized.

Copy link
Author

commented Aug 7, 2019

Yeah, how can I clear the gradle cache? If it's doing gradlew clean I tried that and it didn't work

@Kerooker

This comment has been minimized.

Copy link
Member

commented Aug 7, 2019

I usually first try invalidate and restar, if that doesn't work I delete project's .gradle. If that doesn't work,I delete the global gradle's cache.

One of these usually does that trick for android and me

@cepages

This comment has been minimized.

Copy link
Author

commented Aug 9, 2019

Sorry when you mean invalidate what do you mean:

./gradlew invalidate ?

I assume when you mean restart. you mean restart Android Studio. isn't it?

What you mean with delete project's gradle, you mean removing the build directory?

Sorry, I don't have a wide experience with gradle.

@Kerooker

This comment has been minimized.

Copy link
Member

commented Aug 9, 2019

I meant invalidate and restar, and action from android studio.

The project's gradle: there is a folder with all dependencies called .gradle in your project (perhaps the default view doesn't show it).

There's also the .m2 folder in your (usually, for linux) /home, which also keeps dependencies.

You can also try reimporting the project, if it's in a Github or Bitbucket of some sort

@Kerooker

This comment has been minimized.

Copy link
Member

commented Aug 9, 2019

The thing is that gradle sometimes screws us up A LOT. I myself have troubles with it everytime I change something in my build.gradle.

@Kerooker

This comment has been minimized.

Copy link
Member

commented Aug 9, 2019

You said that Android is bringing JUnit with it. Perhaps your exclude statement is wrong?

If you want, take a look at this project I'm developing Android + KotlinTest with it, and everything is working flawlessly so far

@Kerooker

This comment has been minimized.

Copy link
Member

commented Aug 10, 2019

I'm now getting to the bottom of this issue.

It seems that we're actually defining that class inside KotlinTest, and that is causing these compatibility issues with Espresso, because it brings JUnit platform dependencies to the classpath.

I'll mark this as a bug and investigate further

@Kerooker Kerooker added the bug label Aug 10, 2019

Kerooker added a commit that referenced this issue Aug 10, 2019

Remove JUnit redeclarations
These declarations, although they would reduce the amount of dependencies in our artifacts, were causing issues with other libraries, such as Espresso from Android.

These classes are only used to make IntelliJ know about KT, and enable the green arrow for execution. There's no reason to keep these classes as we're not modifying them.

Fixes #927

Kerooker added a commit that referenced this issue Aug 11, 2019

Remove JUnit redeclarations (#944)
These declarations, although they would reduce the amount of dependencies in our artifacts, were causing issues with other libraries, such as Espresso from Android.

These classes are only used to make IntelliJ know about KT, and enable the green arrow for execution. There's no reason to keep these classes as we're not modifying them.

Fixes #927
@Kerooker

This comment has been minimized.

Copy link
Member

commented Aug 11, 2019

Please try with the snapshot build that was just generated

@lwasyl

This comment has been minimized.

Copy link

commented Aug 19, 2019

Fyi until 3.5 is available the snapshot with fix for this is 3.5.0.2421-SNAPSHOT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.