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 io.mockk.ValueClassSupportKt found" when using in 1.12.0 #722

Closed
3 tasks done
StormPooper opened this issue Oct 13, 2021 · 5 comments
Closed
3 tasks done

Comments

@StormPooper
Copy link

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Expected Behaviour

Android instrumented tests should run.

Current Behaviour

Android instrumented tests fail with Duplicate class io.mockk.ValueClassSupportKt found compilation error (see stack trace below).

Failure Information (for bugs)

When upgrading from 1.11.0 to 1.12.0, tests no longer run. Seems to be affecting others that have commented on #653.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Run tests successfully
  2. Upgrade Gradle dependencies to 1.12.0
  3. Tests fail

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • MockK version: 1.12.0
  • OS: macOS 12
  • Kotlin version: 1.53.1
  • JDK version: 11
  • JUnit version: 5
  • Type of test: android instrumented test

Stack trace

> Task :app:checkDebugAndroidTestDuplicateClasses FAILED
Execution failed for task ':app:checkDebugAndroidTestDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class io.mockk.ValueClassSupportKt found in modules jetified-mockk-agent-android-1.12.0-runtime (io.mockk:mockk-agent-android:1.12.0) and jetified-mockk-agent-jvm-1.12.0 (io.mockk:mockk-agent-jvm:1.12.0)

Minimal reproducible code (the gist of this issue)

dependencies {
	...
    testImplementation "io.mockk:mockk:1.12.0"
    testImplementation "io.mockk:mockk-agent-jvm:1.12.0"
	...
	androidTestImplementation "io.mockk:mockk-android:1.12.0"
    androidTestImplementation "io.mockk:mockk-agent-jvm:1.12.0"
}
@Test
fun noPermission() {
    ActivityScenario.launch(MainActivity::class.java).use {
        onView(withId(R.id.has_permission))
            .check(matches(withText("No permission.")))
    }
}
@HarisHoulis
Copy link

HarisHoulis commented Oct 20, 2021

Could this be happening due to JDK 11 and/or AS Arctic-Fox/Bumblebee?

@HarisHoulis
Copy link

What worked for me was excluding the second module for the androidTestImplementation configuration:

    configurations {
        androidTestImplementation {
            exclude group: 'io.mockk', module: 'mockk-agent-jvm'
        }
    }

@StormPooper
Copy link
Author

@HarisHoulis yep, this workaround works for me too.

@Raibaz Raibaz closed this as completed Jan 13, 2022
@abbisea
Copy link

abbisea commented Mar 17, 2022

Still having this issue on 1.12.3

@azabost
Copy link

azabost commented Mar 23, 2022

What worked for me was excluding the second module for the androidTestImplementation configuration:

    configurations {
        androidTestImplementation {
            exclude group: 'io.mockk', module: 'mockk-agent-jvm'
        }
    }

Any idea how to apply this to all the modules at once?

When I tried this in the top-level (root) build.gradle.kts:

allprojects {
    configurations.findByName("androidTestImplementation")?.run {
        logger.log(LogLevel.LIFECYCLE, "Excluding mockk-agent-jvm from: $projectName")
        exclude(group = "io.mockk", module = "mockk-agent-jvm")
    } ?: run {
        logger.log(LogLevel.LIFECYCLE, "Skipping exclusion of mockk-agent-jvm from: $projectName")
    }
}

then it didn't work. It looks like at this stage the configurations are not prepared yet so there is no way to find androidTestImplementation.

The suggested workaround worked for me only when I added it in the module-specific build.gradle.kts file but I don't want to add it to all of my modules because it's really tedious and easy to forget about, not to mention updating this in the future if necessary.

Do you really think this issue should be closed already? Is there no way for the mockk library to fix this problem?


EDIT (Mar 24 14:44 UTC):

If anyone is interested, I figured out I can exclude mockk-agent-jvm from all the modules at once either by something like:

allprojects {
    afterEvaluate {
        configurations.findByName("androidTestImplementation")?.run { 
            exclude(group = "io.mockk", module = "mockk-agent-jvm")
        }
    }
}

or by extracting the common parts of the module's setup from the android { ... } block from each build.gradle.kts into buildSrc and handling it there, for example something like:

fun Project.removeMockkAgentJvmFromAndroidTests() {
    configurations.findByName("androidTestImplementation")?.run {
        exclude(group = "io.mockk", module = "mockk-agent-jvm")
    }
}

fun Project.defaultAndroidLibrary() = android {
    removeMockkAgentJvmFromAndroidTests()
}

// Then, in each module's build.gradle.kts:

defaultAndroidLibrary()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants