Java 9 modules support (JPMS)
Original discussion: https://github.com/com-lihaoyi/mill/discussions/4368
To avoid confusion, I'll use the term "module" to refer to a Java Module, and "mill module" to disambiguate when necessary.
Requirements:
- [ ] Separate module files for main and test mill modules.
- [ ] Recognize module files, and set classpath/module path accordingly.
- [ ] Option is to add the
Automatic-Module-NameJar manifest attribute. - [ ] Whitebox unit test execution on the classpath.
- [ ] Blackbox integration testing.
- [ ] Whitebox test execution with module patching.
Optional Requirements:
- [ ] Check if the dependency declarations in
mill.buildare in sync with those declared in the module files.
References:
Can modules mix the use of a class-path and a module-path? Or is it either .. or?
Do Kotlin projects use the module path? To my perception, Scala projects don't.
@lefou wrote: Can modules mix the use of a class-path and a module-path?
Is it possible to mix --class-path and --module-path in javac (JDK 9)?
Mixing is absolutely legal. However, modular jars cannot reference non-modular jars on the classpath. Automatic modules (non-modular jars on the modulepath) act as a bridge: modular jars can reference them, and automatic modules can read the classpath.
https://stackoverflow.com/a/46289257/839733
You can use class path and module path in parallel, but there are a few details to consider.
Dependency Module Path ~> Class Path
Explicit modules (JARs with a module descriptor on the module path) can not read the unnamed module (JARs on the class path) - that was done on purpose to prevent modular JARs from depending on "the chaos of the class path".
Since a module must require all of its dependencies and those can only be fulfilled by other named modules (i.e. not JARs on the class path) all dependencies of a modular JAR must be placed on the module path. Yes, even non-modular JARs, which will then get turned into automatic modules.
The interesting thing is that automatic modules can read the unnamed module, so their dependencies can go on the class path.
Dependency Class Path ~> Module Path
If you compile non-modular code or launch an application from a non-modular JAR, the module system is still in play and because non-modular code does not express any dependencies, it will not resolve modules from the module path.
So if non-modular code depends on artifacts on the module path, you need to add them manually with the --add-modules option. Not necessarily all of them, just those that you directly depend on (the module system will pull in transitive dependencies) - or you can use ALL-MODULE-PATH (check the linked post, it explains this in more detail).
Five Command Line Options To Hack The Java Module System
@lefou wrote: Do Kotlin projects use the module path?
Provide documentation how to configure Gradle Kotlin compilation with Java JPMS enabled
@lefou wrote: Scala projects don't
Can you name some real-world projects, that make use of JPMS? We could then add some of them to our third-party example test suite to check our compatibility.