Kotlin / kotlinx.collections.immutable

Immutable persistent collections for Kotlin
Apache License 2.0
1.12k stars 56 forks source link

Provide module-info descriptor for java 9 and later #157

Open daniel-jasinski opened 7 months ago

daniel-jasinski commented 7 months ago

It would be great if this library was provided as a multi-release jar with module-info.class descriptor, so that it could be part of the Java module system.

Sporking commented 6 months ago

Yes, please do this!

qurbonzoda commented 5 months ago

Hi @daniel-jasinski, To better understand the specific use cases and motivations behind this feature request, we would greatly appreciate it if you could provide us with more details.

Your insights will be invaluable in guiding our decision-making process and ensuring that any enhancements align closely with the needs of our user community.

daniel-jasinski commented 5 months ago

Hi, We are developing a desktop application with Compose-Multiplatform UI. The app is packaged using JDK jpackage utility, and would like to make the app modular using JMS for various build hygiene and performance reasons. It would simplify our process if we did not have to do workarounds for some of our non-modular dependencies.

sgammon commented 4 months ago

@qurbonzoda The development experience without a module descriptor can be quite frustrating, for example, in IDEA:

Screenshot 2024-02-23 at 12 10 33 AM

But, from Gradle:

> Task :protocol:compileJava FAILED
/.../module-info.java:9: error: module not found: kotlinx.collections.immutable.jvm
  requires kotlinx.collections.immutable.jvm;

This is probably either originating from a Automatic-Module-Name, or from a generated module name from somewhere in IntelliJ. I'm not sure where, but the suggestion is wrong, and if I don't add the incorrect requires ... line, the code flags as an error in the IDE.

What specific scenarios or projects would benefit from the integration of kotlinx.collections.immutable into the Java module system?

Any scenario where the developer is using KotlinX Immutable Collections and wishes to distribute or package their own library or application with JPMS. Without the module descriptor in this library, the author has these choices:

This is, unfortunately, the JPMS hand dealt to all of us by Oracle. Because of all the reasons above, KotlinX Serialization builds with a module-info, as do coroutines, datetime, and atomicfu. Thus, a user adding the full suite of KotlinX libraries may be in for a surprising and frustrating realization when this library does not provide one.

Edit: For anyone running into this issue in IDEs, you can suppress with:

@Suppress("JAVA_MODULE_DOES_NOT_DEPEND_ON_MODULE")
qurbonzoda commented 4 months ago

@sgammon, thank you for your elaborate answer. We will aim to include module-info in our upcoming releases.

qwwdfsad commented 4 months ago

@qurbonzoda you can probably take a look at https://github.com/Kotlin/kotlinx.coroutines/blob/master/buildSrc/src/main/kotlin/Java9Modularity.kt to save an effort

sgammon commented 4 months ago

@qwwdfsad / cc @qurbonzoda I've posted a PR which uses Java9Modularity to ship a module-info. Let me know if you need any changes or have other review notes.