Kotlin / kotlinx.coroutines

Library support for Kotlin coroutines
Apache License 2.0
13.02k stars 1.85k forks source link

Ambiguous module reference: kotlinx.coroutines.core #3842

Open oryan-block opened 1 year ago

oryan-block commented 1 year ago

Describe the bug

I'm trying to upgrade to v1.7.3 and add the modules to a module-info file but it seems that kotlinx-coroutines-core and kotlinx-coroutines-core-jvm cause a problem because they have the same module name (I think)

image

My pom dependencies:

        <dependency>
            <groupId>org.jetbrains.kotlinx</groupId>
            <artifactId>kotlinx-coroutines-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlinx</groupId>
            <artifactId>kotlinx-coroutines-jdk9</artifactId>
        </dependency>

This seems to happen because kotlinx-coroutines-core-jvm is a dependency of kotlinx-coroutines-jdk9 and it's module name is kotlinx-coroutines-core. At the same time kotlinx-coroutines-core has an implied module name which is its package name. Am I importing these dependencies wrong?

qwwdfsad commented 1 year ago

Would it be okay for you to attach a reproducing project?

I'm trying to upgrade to v1.7.3

Could you please elaborate on what version you are upgrading from?

oryan-block commented 1 year ago

@qwwdfsad try to checkout this branch: https://github.com/graphql-java-kickstart/graphql-java-tools/tree/upgrade-java-11

Upgrading from v1.6.4

oryan-block commented 1 year ago

btw if I replace these deps with kotlinx-coroutines-core-jvm the warning is gone, but that doesn't seem to be the way to import the project according to the docs

mjovanc commented 1 year ago

@oryan-block Is this still an issue for you? The way I see it you should not add the extension -jvm, it should only be kotlinx-coroutines-core. The packages for the specific platform will be present and common ones.

I could not find the branch now to test.

oryan-block commented 1 year ago

@mjovanc yes this is still a problem. This happens even if I only import kotlinx-coroutines-core Please check this branch: https://github.com/graphql-java-kickstart/graphql-java-tools/tree/coroutinies-module-reference

dkhalanskyjb commented 8 months ago

In Maven projects, it's ok to depend on the -jvm variant of the Kotlin Multiplatform libraries. In fact, it's more straightforward: all kotlinx-coroutines-core should do in Maven is specify a dependency on kotlinx-coroutines-core-jvm for convenience. I'm not sure why also having kotlinx-coroutines-core in the dependencies causes a warning. Is it only in the IDE, or can you observe it when building the project?

oryan-block commented 8 months ago

@dkhalanskyjb it's not just the IDE, maven also fail to build because it can't see anything in the ambiguous module. Depending on -jvm fixes it. Should the readme be fixed?

I'm not sure why also having kotlinx-coroutines-core in the dependencies causes a warning

Not 100% sure but I do believe it's because both core and core-jvm end up with the same module name.