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

Ambiguous JPMS module reference in maven projects #2901

Open
fzhinkin opened this issue Jan 8, 2025 · 2 comments
Open

Ambiguous JPMS module reference in maven projects #2901

fzhinkin opened this issue Jan 8, 2025 · 2 comments
Assignees

Comments

@fzhinkin
Copy link
Contributor

fzhinkin commented Jan 8, 2025

In maven projects, published "umbrella" artifacts (like "kotlinx-serialization-json") works as a gateway to corresponding -jvm artifacts. The former do not have a JPMS module bundled inside, so the module name is inferred from the artifact name. As a result, there are two artifacts providing the same module:

  • kotlinx-serialization-json provides kotlinx.serialization.json as it was inferred from the module name.
  • kotlinx-serialization-json-jvm provides kotlinx.serialization.json, well, because it actually provides it.

To Reproduce

Here's a reproducer: https://github.com/fzhinkin/kotlinx-serialization-jpms-conflict

$ mvm compile
...
[WARNING] /Users/filipp.zhinkin/.m2/repository/org/jetbrains/kotlinx/kotlinx-serialization-json-jvm/1.8.0/kotlinx-serialization-json-jvm-1.8.0.jar: (-1, -1) The root is ignored because a module with the same name 'kotlinx.serialization.json' has been found earlier on the module path at: /Users/filipp.zhinkin/.m2/repository/org/jetbrains/kotlinx/kotlinx-serialization-json/1.8.0/kotlinx-serialization-json-1.8.0.jar
[ERROR] /Users/filipp.zhinkin/Development/kotlinx-serialization-jmps-conflict/src/main/kotlin/Dummy.kt: (4, 30) Unresolved reference 'json'.
[ERROR] /Users/filipp.zhinkin/Development/kotlinx-serialization-jmps-conflict/src/main/kotlin/Dummy.kt: (10, 33) Unresolved reference 'Json'.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE

Expected behavior

"Umbrella" artifacts like kotlinx-serialization-core or kotlinx-serialization-json should provide some JPMS modules that won't clash with modules provided by actual ***-jvm artifacts.

@fzhinkin fzhinkin added the build label Jan 8, 2025
@fzhinkin
Copy link
Contributor Author

fzhinkin commented Jan 8, 2025

See corresponding issue in coroutines: Kotlin/kotlinx.coroutines#3842

@JakeWharton
Copy link
Contributor

In both of these libraries this is a result of your own configuration. See here and there.

Instead of making the metadata/common artifact depend on the JVM one, have you considered a relocation pom instead?

Another option would be to publish the JVM artifacts using the unsuffixed artifactId and move the metadata/common artifact to have a -common suffix. The Gradle module metadata will still be published with the unsuffixed artifact allowing both Maven and Gradle users to continue to consume it. This is what the stdlib does: https://search.maven.org/search?q=kotlin-stdlib.

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

No branches or pull requests

2 participants