--module-source-path option implementation in javac

Eugene Zhuravlev jeka at intellij.com
Tue Oct 18 07:09:31 UTC 2016


Hi dev. list members,

We at JetBrains are working on jigsaw-related javac features support in 
IntelliJ IDEA. Namely, the --module-source-path parameter.
This option is important when multiple modules are compiled at the same 
time. While the IDE compiles modules one-by-one, there are certain 
situations where we have to use multi-module compilation. For example, 
the case when module-info files for different modules reference each other:

module-info.java in module A:
module a {
   exports a to b;
}


module-info.java in module B:
module b {
   requires a;
}

Here we have to compile sources for module A and module B together in 
one compile session and use --module-source-path parameter so that javac 
is able to resolve both module descriptors.

My recent investigations show that current javac implementation assumes 
certain disk layout for the source files that form a module. This leads 
to restrictions on the --module-source-path argument value. Currently 
this value is a list of paths where every path may optionally a "*" 
wildcard denoting any directory on particular file system level. The 
code responsible for --module-source-path option support is located in 
com.sun.tools.javac.file.Locations.ModuleSourcePathLocationHandler.init()

The code here works differently depending on whether the path element 
contains an optional '*' wildcard or not. If the path contains the 
wildcard, the directory name matching this wildcard will be assumed 
equal to module name (which is another problem) and the path to the 
module descriptor file is configured correctly.
If there is no wildcard in the path, the path is not used "as is", but 
instead its direct sub-directories are analyzed and used as roots where 
module-info.java can be found. The latter looks more like a bug than 
intended behavior.

 From the IDE's point of view there is no need to use "*" wildcards, 
since the "too much typing" is not an issue for the program. Another 
reason is that the usage of wildcards is possible only for certain 
layouts of module A and B sources. In general case, when modules contain 
several source roots on different file system levels, the usage of 
wildcards is not possible.
So enumeration of absolute paths to source roots is the only option 
available for the IDE. Due to the problem mentioned above this does not 
work either. The IDE could have created the paths with wildcards and 
this would have worked for some project layouts, but the assumption that 
the directory name is equal to module name looks too strict and should 
not be true for many real-life project layouts.

So the questions are:
- Are there any changes planned for the command line interface to 
address these issues?
- If current command line behavior is correct and intended for some 
certain situations only, we would kindly ask to consider making module 
source path configuration more flexible via the compiler tooling API, 
which is used by IDEs. However, keeping command line interface and 
tooling API consistent is a good idea too.

Thanks in advance for any comments on the problem,

-- 

Best regards,

Eugene Zhuravlev
Software Developer
JetBrains
http://www.jetbrains.com
The Drive to Develop


More information about the jigsaw-dev mailing list