I am trying to acquaint myself with Java 9 modules and how to define them in IntelliJ. Among other things, I want to solve a split package problem using the --patch-module compiler/JVM flag and I don't know how to make it work in IntelliJ.
I am using IntelliJ IDEA 2017.2.1 Build #IC 172.3544.35 with Java HotSpot(TM) 64-Bit Server VM (build 9+180, mixed mode).
This is my source file MyImmutableList.java:
package com.google.common.collect;
public class MyImmutableList extends RegularImmutableList {
public MyImmutableList(Object[] array) {
super(array);
}
}
It belongs to my module com.effjava.collect with module-info.java:
module com.effjava.collect {
// do not require module guava; instead patch this module with guava.19-0.jar via:
// javac --patch-module com.effjava.collect=guava-19.0.jar module-info.java com/google/common/collect/MyImmutableList.java
// requires guava;
exports com.google.common.collect;
}
For the compilation of my modules, I specified the --patch-module flag in IntelliJ using Settings => Build,Execution,Deplyoment => Compiler => Shared build process VM options as described here.
The compilation fails because the compiler cannot find the superclass RegularImmutableList from the guava library.
The advice provided by IntelliJ is to add a requires directive for the guava library to the module descriptor, which of course does not work because the compiler then rightly complains about the split package problem:
Error:java: module guava reads package com.google.common.collect from both com.effjava.collect and guava
On further investigation, I noticed that the build process issues a warning related to the --patch-module flag saying:
Error:Abnormal build process termination: "C:\Program Files\Java\jdk-9\bin\java" -Xmx700m -Djava.awt.headless=true
... lots of stuff ...
WARNING: Unknown module: com.effjava.collect specified to --patch-module
... more stuff ...
BTW, I did not know how to get hold of the compiler warnings. I do not hide them in IntelliJ's message window and yet I cannot see them. As a workaround, I simply specified bogus compiler flags and let the build process crash so that it emitted the WARNING in its crash report.
Anyway, the build process complains - while building the module - that the module in question does not exist and for this reason cannot be patched via --patch-module. This complaint does not make sense because I did successfully compile and build my module by typing in the javac and jarcommands manually on the command line level:
cd %PROJECTDIR%\com.effjava.collect\src
javac --patch-module com.effjava.collect=../../guava/guava-19.0.jar -d ../../out/production/com.effjava.collect module-info.java com/google/common/collect/MyImmutableList.java
jar --create --file=../../out/artifacts/com_effjava_collect_jar/com.effjava.collect.jar -C ../../out/production/com.effjava.collect .
How can I tell IntelliJ's build process that I want to patch my module?


javaccommand by hand. In fact, I have a batch file that compiles all my modules with the--patch-moduleflag, creates all the modular jars, and eventually runs the main module with the--patch-moduleflag. The problem is just with IntelliJ. How can I tell IntelliJ that I want to patch a module? - alanger