I followed the Gradle guide on building Java 9 modules to get a simple Java 9-based library project off the ground. In particular I followed the advice in the guide to manually set my module path like so:
ext.moduleName = 'com.foo.bar'
compileJava {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
]
classpath = files()
}
}
Observe that this is just taking my entire classpath, as determined by Gradle from my dependency graph, and shifting it onto the module path.
Everything works wonderfully except for one simple problem. Some of my dependencies (eg org.jetbrains.kotlin:kotlin-stdlib-1.2.10
) aren't real Java 9 modules since they lack a module-info.class
. It's fine to stick them on the classpath or module path because, for now, java
will convert them into so-called automatic modules.
The problem arises because even for an automatic module, if it is on my module path, I need to refer to it in a requires
directive in my project's modules. But because I roll with the -Xlint:all
option to the Java compiler, javac
generates the following warning:
/path/to/myproject/foo-module/src/main/java/module-info.java:26: warning: requires directive for an automatic module
requires kotlin.stdlib;
^
This warning is untenable for me because I also roll with the -Werror
javac
flag, so it makes my build fail.
So it seems I need to push the automatic modules onto my classpath and only keep "true" module dependencies on the module path...
Is there any general or semi-general way (ie that is not coupled to dependency names) to split my dependencies between the compiler classpath and its module path?