Skip to content

Java module not found: kotlinx.io.core.jvm #401

Closed
@ForteScarlet

Description

@ForteScarlet

Hi! I am trying to use kotlinx-io in a project with java modules.

module-info.java

module forte.kotlinx.io.test {
    requires kotlin.stdlib;

}

Example.kt

fun read(source: Source) = source.readByteArray()

fun run() {
    val source = ByteArrayInputStream(byteArrayOf(0)).asSource()
    println(source.buffered().use(::read).contentToString())
}

fun main() {
    run()
}

If I don't requires kotlinx.io.core.jvm in module-info, then I get the following error:

> Task :compileKotlin FAILED
e: file:///IdeaProjects/kotlinx-io-modules-test/src/main/kotlin/love/forte/ktxiotest/Example.kt:10:18 Symbol is declared in module 'kotlinx.io.core.jvm', which the current module does not depend on.
e: file:///IdeaProjects/kotlinx-io-modules-test/src/main/kotlin/love/forte/ktxiotest/Example.kt:10:35 Symbol is declared in module 'kotlinx.io.core.jvm', which the current module does not depend on.
e: file:///IdeaProjects/kotlinx-io-modules-test/src/main/kotlin/love/forte/ktxiotest/Example.kt:13:55 Symbol is declared in module 'kotlinx.io.core.jvm', which the current module does not depend on.
e: file:///IdeaProjects/kotlinx-io-modules-test/src/main/kotlin/love/forte/ktxiotest/Example.kt:14:20 Symbol is declared in module 'kotlinx.io.core.jvm', which the current module does not depend on.
e: file:///IdeaProjects/kotlinx-io-modules-test/src/main/kotlin/love/forte/ktxiotest/Example.kt:14:31 Symbol is declared in module 'kotlinx.io.core.jvm', which the current module does not depend on.

If I add the requires:

module forte.kotlinx.io.test {
    requires kotlin.stdlib;
    requires kotlinx.io.core.jvm;

}

I got:

> Task :compileJava FAILED
/Users/forte/IdeaProjects/kotlinx-io-modules-test/src/main/java/module-info.java:3: error: module not found: kotlinx.io.core.jvm
    requires kotlinx.io.core.jvm;
                            ^

My build.gradle.kts:

plugins {
    application
    kotlin("jvm") version "2.0.20"
}

group = "love.forte"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

// https://kotlinlang.org/docs/gradle-configure-project.html#configure-with-java-modules-jpms-enabled
tasks.named("compileJava", JavaCompile::class.java) {
    options.compilerArgumentProviders.add(CommandLineArgumentProvider {
        // Provide compiled Kotlin classes to javac – needed for Java/Kotlin mixed sources to work
        listOf("--patch-module", "forte.kotlinx.io.test=${sourceSets["main"].output.asPath}")
    })
}

application {
    mainClass = "love.forte.ktxiotest.ExampleKt"
}

dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-io-core:0.5.4")
    testImplementation(kotlin("test"))
}

tasks.test {
    useJUnitPlatform()
}
kotlin {
    jvmToolchain(21)
}

It seems that JPMS is not yet supported by kotlinx-io?
Maybe an explicit module definition or auto-module needs to be added for it,
or am I using it the wrong way somewhere?

Metadata

Metadata

Assignees

Labels

infraintegrationAn issue related to the integration with other libraries or platform-specific APIs

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions