nort3x / Event4k

eventbus library for kotlin multiplatform
MIT License
9 stars 0 forks source link

Transitive dependency on event4k-native causes incompatibility with JVM targets #1

Open tieskedh opened 1 year ago

tieskedh commented 1 year ago

Hello,

I encountered an issue while using the event4k library in my Kotlin Multiplatform project. My project is targeting the JVM platform, but I noticed that there's a transitive dependency on event4k-native, which causes the build to fail. Here's the error message I encountered:

> Could not resolve all files for configuration ':kern:jvmCompileClasspath'.
   > Could not resolve com.github.nort3x.event4k:event4k-native:1.0.0.
     Required by:
         project :kern > com.github.nort3x:event4k:1.0.0
      > No matching variant of com.github.nort3x.event4k:event4k-native:1.0.0 was found. The consumer was configured to find a library for use during compile-time, preferably optimized for standard JVMs, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but:
          - Variant 'nativeApiElements-published' capability com.github.nort3x.event4k:event4k-native:1.0.0 declares a library:
              - Incompatible because this component declares a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed a component for use during compile-time, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)

By excluding the event4k-native dependency from my project, I was able to resolve this issue:

val jvmMain by getting {
    dependencies {
        implementation("com.github.nort3x:event4k:1.0.0") {
            exclude(group = "com.github.nort3x.event4k", module = "event4k-native")
        }
    }
}

Could you please look into this issue and consider updating the library to exclude the event4k-native dependency for JVM targets or provide an alternative compatible dependency?

Thank you!


Ps. ChatGPT4 diagnosed and recommended the update-request.

nort3x commented 1 year ago

thanks for informing me, can i have your build.gradle file as a reference? @tieskedh

tieskedh commented 1 year ago

Mu current build.gradle file is:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("multiplatform")
}

kotlin{
    jvm{
        jvmToolchain(8)
    }

    sourceSets{
        val commonMain by getting{
            dependencies {
                implementation(kotlin("stdlib-common"))
                implementation("app.softwork:kotlinx-uuid-core:0.0.18")
                implementation("io.insert-koin:koin-core:3.4.0")
                api("com.github.nort3x:event4k:1.0.0")  {
                    exclude(module = "event4k-native")
                }
                implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.0-RC")
            }
        }
    }
}

tasks.withType<KotlinCompile>().configureEach {
    kotlinOptions {
        freeCompilerArgs += "-Xopt-in=nl.scauting.port.IAmForPorts"
    }
}

group = "nl.scauting"
version = "1.0"

With Kotlin being version "1.8.20"