6

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?

0xbe5077ed
  • 4,565
  • 6
  • 35
  • 77
  • Possible duplicate of [Unable to derive module descriptor for auto generated module names in Java 9?](https://stackoverflow.com/questions/46501388/unable-to-derive-module-descriptor-for-auto-generated-module-names-in-java-9) – Naman Dec 27 '17 at 05:05
  • The reason why I have voted this as duplicate is that the (2) alternate specified in the existing answer could help you avoid the automatic module name generation and I hope you understand that the warning is justified anyway. – Naman Dec 27 '17 at 05:15
  • This question definitely does not look like a duplicate of the linked question. @0xbe5077ed Did you get anywhere with this – Daniel Scott Jul 23 '18 at 14:31
  • This is definitely not a duplicate. This is about breaking the dependencies across module-path and class-path. I too am trying to do that same split. – Chris Kessel Oct 11 '19 at 17:16

0 Answers0