kosi-libs/MocKMP

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

vdshb opened this issue · 4 comments

vdshb commented

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.

Version 1.9.0 published with the fix.

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)]

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.

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