Specifying -Xmodule-path value in -Xbuild-file XML file for kotlinc


#1

For kotlinc 1.2.70 (or newer), how can I specify a value for -Xmodule-path in an XML file used as the value of the -Xbuild-file option?

The following command line compiles fine:

kotlinc -d build -Xmodule-path=lib/kotlin-stdlib-1.2.70.jar src/main/java/module-info.java src/main/kotlin/com/example/Test.kt

Where Test.kt contains an empty com.example.Test class, and where module-info.java contains:

module com.example {
	requires kotlin.stdlib;
	exports  com.example;
}

The following command line:

kotlinc -Xbuild-file=build-file.xml -Xmodule-path=lib/kotlin-stdlib-1.2.70.jar

Outputs the following error:

error: module kotlin.stdlib cannot be found in the module graph

Where build-file.xml contains:

<modules>
    <module name="test-module" type="java-production" outputDir="build">
        <sources path="src/main/kotlin/com/example/Test.kt"/>
        <javaSourceRoots path="src/main/java"/>
    </module>
</modules>

#2

-Xmodule-path is ignored when sources/dependencies are specified via the build file. May I ask what do you use build files for to find out if there’s a workaround? This is an internal format that is subject to change in any release without notice.


#3

I’m writing a Gradle plugin to support JPMS modules.

I’m trying to support KotlinCompile using JPMS modules, but KotlinCompile always generates a build file for -Xbuild-file.

There doesn’t seem to be any way to prevent KotlinCompile from using -Xbuild-file, so I looked into whether build files support an element that corresponds to -Xmodule-path. I didn’t see any support in the code, so I figured I’d ask about it here.

Are there any plans to either support module-path in a build file, -Xmodule-path in conjunction with a build file, or some way to instruct KotlinCompile to not use a build file?

As a secondary question, are there any plans to add support to kotlinc & KotlinCompile for equivalents for other javac module options, like --patch-module (which I assume would be -Xpatch-module= for kotlinc)?


#4

Thanks for the details!

Are there any plans to either support module-path in a build file, -Xmodule-path in conjunction with a build file, or some way to instruct KotlinCompile to not use a build file?

I think the intended way would be to support module paths in the build files. I don’t see any major obstacle with this. Could you please file an issue at https://kotl.in/issue (and maybe consider contributing the implementation :wink:)?

As a secondary question, are there any plans to add support to kotlinc & KotlinCompile for equivalents for other javac module options, like --patch-module (which I assume would be -Xpatch-module= for kotlinc )?

Yes, there are plans to catch up with javac under https://youtrack.jetbrains.com/issue/KT-20740.