Closed TheMrMilchmann closed 1 year ago
requires kotlinx.coroutines.core.jvm;
/Projects/java-demo/src/main/java/module-info.java:3: 错误: 找不到模块: kotlinx.coroutines.core.jvm
requires kotlinx.coroutines.core.jvm;
I use kotlinx coroutines with jpms in my project. But I got error "cannot find module: kotlinx.coroutines.core.jvm". Does kotlinx coroutines not support jpms even using automatic module ?
As a stop gap, for now add
addExtraDependencies("kotlinx.coroutines")
to your JLink gradle settings, it allows it to find coroutines
This stopgap doesn't work for me. First there is no "kotlinx.coroutines" I can add to module-info. I can get IntelliJ to accept kotlinx.coroutines.core.jvm … But trying to add any with addExtraDependencies doesn't help, it still says:
src/main/kotlin/module-info.java:6: error: module not found: kotlinx.coroutines.core.jvm
requires kotlinx.coroutines.core.jvm;
or
src/main/kotlin/module-info.java:6: error: module not found: kotlinx.coroutines
Hi, have there been any further developments regarding this issue?
anyone know how to fix this?
It happens whenever I launch a coroutine, the program compiles and runs fine, but then throws and exception when the coroutine is called.
It happens because you are using JDK 16. Previously, an illegal access was only logged once and your program would continue to run. Since JDK 16 the new default behavior is to throw an exception. See https://openjdk.java.net/jeps/396 for more details.
You can use this JVM argument as a workaround: --illegal-access=permit
Note that there are a lot of libraries that make use of this now considered illegal (reflective) access. Eventually they should all be fixed / refactored, but I have no idea how realistic that would be.
@lion7 thanks so much i've been banging my head against the wall trying to figure out what this meant.
@lion7 weird so I enabled --illegal-access=permit through out all my gradle settings & configuration stuff where there was an xmx. running through gradle, its fine, there's no exceptions. its only when I run through intellij idea's gradle task does it throw an exception, even though in that run configuration i have it set.
The VM options in your run configuration are passed to the Gradle JVM and not your application. You would probably have to configure it somewhere in your jpackage config, so that the packaged application will run with that parameter. Note that the run
will fork a new JVM, so that one probably is still missing this JVM param.
Yeah I did do that, but the fact that its happening only in intellij says something weird is going on. I even set idea's own jvm parameters to have it. it even starts up the gradle task with 8:32:55 AM: Executing task 'run --illegal-access=permit'...
downgrading to kotlin 1.4.3 dependencies didn't work either
@abueide Have u solved the problem? I have the same error .
Exception in thread "JavaFX Application Thread" java.lang.IllegalAccessError: class kotlin.coroutines.jvm.internal.DebugProbesKt (in module kotlin.stdlib) cannot access class kotlinx.coroutines.debug.internal.DebugProbesImpl (in module kotlinx.coroutines.core.jvm) because module kotlin.stdlib does not read module kotlinx.coroutines.core.jvm at
@lazyii no sadly i never figured it out. I ended up switching to badassruntime so I didn't have to deal with the modules system.
The JVM parameter --add-reads kotlin.stdlib=kotlinx.coroutines.core.jvm
should help with it.
@p-schneider thx. config below: application { ....... applicationDefaultJvmArgs = listOf("--add-reads", "kotlin.stdlib=kotlinx.coroutines.core.jvm") } When i click debug, i can be executed.
But when i click run, it still throws an exception. "module kotlin.stdlib does not read module kotlinx.coroutines.core.jvm ....."
/(ㄒoㄒ)/~~
For some reason IntelliJ ignores the applicationDefaultJvmArgs setting in some cases when running via gradle. (See https://youtrack.jetbrains.com/issue/KTIJ-18424) So running gradle run from intellij would fail, but "gradlew run" from the console would succeed. In my project as a workaround I ended up adding an additional task to copy all modules/libs into a specific folder and then run it as a "Kotlin" type run configuration instead of gradle run.
@p-schneider yeah this is exactly what I experienced as well
I created a PR which adds a dedicated
Whoops, wrong repo / issue..
Anyway, I'm working on a PR to add JPMS support to kotlinx.coroutines. The biggest challenge is probably to add JPMS support to upstream libraries / dependencies first. My progress can be found here: https://github.com/lion7/kotlinx.coroutines/module-info
: https://github.com/Kotlin/kotlinx-datetime/pull/135
@lion7 did you make any headway with this?
Not much, compilation fails because kotlinx.atomicfu
is not a module.
So still waiting for https://github.com/Kotlin/kotlinx.atomicfu/pull/201 to be merged.
Any reason why https://github.com/Kotlin/kotlinx.coroutines/pull/2901 has not been merged yet?
Im also having this issue! Would love to see it fixed
It has been…. 5? years since the release of JPMS, and it has been 6 months since a fix has been posted.
Can SOMEONE please merge #2901?
“Hacking” JPMS for a project that, with quite literally 2 mouse clicks, could support JPMS is just frustrating beyond belief.
Maybe @qwwdfsad can help figure this out?
FWIW, getting #2901 merged is certainly a step forwards, but @lion7 's blocked (stalled?) change for full JPMS support is the big win.
I opened PR https://github.com/Kotlin/kotlinx.coroutines/pull/3297 with full support for JPMS. However, there is still an open issue with highlighting in IntelliJ IDEA that is kind of annoying...
I've published 1.7.0-jpms-preview
to https://maven.pkg.jetbrains.space/public/p/kotlinx-coroutines/maven
repository; if you are relying on JPMS in your project, consider checking it out before JPMS support is released
@abueide Have u solved the problem? I have the same error .
Exception in thread "JavaFX Application Thread" java.lang.IllegalAccessError: class kotlin.coroutines.jvm.internal.DebugProbesKt (in module kotlin.stdlib) cannot access class kotlinx.coroutines.debug.internal.DebugProbesImpl (in module kotlinx.coroutines.core.jvm) because module kotlin.stdlib does not read module kotlinx.coroutines.core.jvm at
I recently had the same issue while debugging using IntelliJ, used this fix
disable the coroutine agent in settings
I'm quoting directly from https://github.com/Kotlin/kotlinx.serialization/issues/940 because the same reasoning applies:
Additionally,
jlink
andjpackage
) is extremely handy and I would love to usekotlinx.coroutines
without additional non-trivial build-system hacks.kotlinx.coroutines
is not possible because the latter does not have a stable module name.A temporary (and fairly simple) solution for
2.
would be providing stableAutomatic-Module-Name
entries.