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

org.kodein.mock:mockmp-test-helper-jvm conflicts with org.jetbrains.kotlin:kotlin-test-junit5 during jvmTest #31

Closed
vdshb opened this issue Jul 15, 2022 · 4 comments

Comments

@vdshb
Copy link

vdshb commented Jul 15, 2022

org.kodein.mock:mockmp-test-helper-jvm contains org.jetbrains.kotlin:kotlin-test-junit as a dependency.

org.jetbrains.kotlin:kotlin-test-junit5 and org.jetbrains.kotlin:kotlin-test-junit conflict with each other.

When project configured to use junit5 and we add mocKMP helper to it then we'll get compile time exception on running jvmTest:

Execution failed for task ':jvmTest'.
> Could not resolve all files for configuration ':jvmTestRuntimeClasspath'.
   > Could not resolve org.jetbrains.kotlin:kotlin-test-junit5:1.7.10.
     Required by:
         project : > org.jetbrains.kotlin:kotlin-test:1.7.10
      > Module 'org.jetbrains.kotlin:kotlin-test-junit5' has been rejected:
           Cannot select module with conflict on capability 'org.jetbrains.kotlin:kotlin-test-framework-impl:1.7.10' also provided by [org.jetbrains.kotlin:kotlin-test-junit:1.7.0(junitRuntime)]
   > Could not resolve org.jetbrains.kotlin:kotlin-test-junit:1.7.0.
     Required by:
         project : > org.kodein.mock:mockmp-test-helper:1.8.1 > org.kodein.mock:mockmp-test-helper-jvm:1.8.1
      > Module 'org.jetbrains.kotlin:kotlin-test-junit' has been rejected:
           Cannot select module with conflict on capability 'org.jetbrains.kotlin:kotlin-test-framework-impl:1.7.0' also provided by [org.jetbrains.kotlin:kotlin-test-junit5:1.7.10(junit5Runtime)]

Reproducer:

build.gradle.kts:

plugins {
    kotlin("multiplatform") version "1.7.10"
    id("org.kodein.mock.mockmp") version "1.8.1"
}

group = "com.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

mockmp {
    usesHelper = true
}

kotlin {
    jvm {
        compilations.all {
            kotlinOptions.jvmTarget = "1.8"
        }
        withJava()
        testRuns["test"].executionTask.configure {
            useJUnitPlatform()
        }
    }
    js(BOTH) {
        browser {
            commonWebpackConfig {
                cssSupport.enabled = true
            }
        }
    }

    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val jvmMain by getting
        val jvmTest by getting
        val jsMain by getting
        val jsTest by getting
    }
}

src/commonTest/kotlin/com/example/ExampleTest.kt:

package com.example

import kotlin.test.Test
import kotlin.test.assertEquals

class ExampleTest {

    @Test
    fun should_work() {
        assertEquals(1,1)
    }
}

Switching to Junit4 (useJUnitPlatform()' -> 'useJUnit()) or removing mocKMP helper (usesHelper = true -> usesHelper = false) make test runnable again.

@SalomonBrys
Copy link
Member

Version 1.9.0 published with the fix.

@stefanmatar
Copy link

I am still getting this issue with 0.11.0

I defined usesHelper = false and useJUnitPlatform()

Execution failed for task ':kspTestKotlinJvm'.
> Error while evaluating property 'filteredArgumentsMap' of task ':kspTestKotlinJvm'
   > Could not resolve all files for configuration ':jvmTestCompileClasspath'.
      > Could not resolve org.jetbrains.kotlin:kotlin-test-junit:1.7.22.
        Required by:
            project :
         > Module 'org.jetbrains.kotlin:kotlin-test-junit' has been rejected:
              Cannot select module with conflict on capability 'org.jetbrains.kotlin:kotlin-test-framework-impl:1.7.22' also provided by [org.jetbrains.kotlin:kotlin-test-junit5:1.7.22(junit5Api), org.jetbrains.kotlin:kotlin-test-junit5:1.7.21(junit5Api)]
      > Could not resolve org.jetbrains.kotlin:kotlin-test-junit5:1.7.22.
        Required by:
            project : > org.jetbrains.kotlin:kotlin-test:1.7.22
         > Module 'org.jetbrains.kotlin:kotlin-test-junit5' has been rejected:
              Cannot select module with conflict on capability 'org.jetbrains.kotlin:kotlin-test-framework-impl:1.7.21' also provided by [org.jetbrains.kotlin:kotlin-test-junit:1.7.22(junitApi)]

@SalomonBrys
Copy link
Member

You need to use:

mockmp {
    usesHelper = true
}
kotlin {
    sourceSets {
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
                implementation("org.kodein.mock:mockmp-test-helper:0.11.0")
            }
        }
    }
}

I'll reopen this issue because I forgot to document this.
Furthermore, the Gradle plugin should apply the correct Junit helper.

@SalomonBrys SalomonBrys reopened this Dec 20, 2022
@SalomonBrys
Copy link
Member

The 1.12.0 Gradle plugin applies the correct dependency according to your test framework.
Thanks for the report !

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

3 participants