I’ve setup a small minimal example Gradle 7.6 project which uses JDK 19 and Scala. Compilation of Java and Scala is done without any errors, however as soon as I run the “application” the JVM is unable to find Scala’s Predef:
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Predef$
at eu.geekplace.beanstalk.core/eu.geekplace.beanstalk.core.scala.BeanstalkScala.sayHello(BeanstalkScala.scala:4)
at eu.geekplace.beanstalk.app/eu.geekplace.beanstalk.app.App.main(App.java:7)
Caused by: java.lang.ClassNotFoundException: scala.Predef$
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 2 more
even though, I believe Predef’s class is in classpath, since scala-library-2.13.10.jar, which apparently contains Predef, is in the classpath. Checked via invoking gradle with --debug, which shows the following arguments being passed to the JVM when executing the application
You are right, I assumed that Java modules have implicit full access to traditional non-module libraries. This is not the case, so I added --add-reads eu.geekplace.beanstalk.core=ALL-UNNAMED to grant my module access to the unnamed module. However, it appears that Gradle constructs a wrong command line when executing the JVM in order to run the app: Scala’s runtime libraries are put in the module path and not in the class path, even though, they are not modular. See
Thanks for pointing this out (also in the gradle bug. However if I add requires org.scala.lang.scala3.library; to my module-info.java, then I get the following warnings:
error: the unnamed module reads package scala from both scala.library and org.scala.lang.scala3.library
error: the unnamed module reads package scala.util from both scala.library and org.scala.lang.scala3.library
error: the unnamed module reads package scala.util.control from both scala.library and org.scala.lang.scala3.library
error: the unnamed module reads package scala.runtime from both scala.library and org.scala.lang.scala3.library
error: the unnamed module reads package scala.reflect from both scala.library and org.scala.lang.scala3.library
error: the unnamed module reads package scala.annotation from both scala.library and org.scala.lang.scala3.library
error: module scala.library reads package scala from both org.scala.lang.scala3.library and scala.library
error: module scala.library reads package scala.util from both org.scala.lang.scala3.library and scala.library
error: module scala.library reads package scala.util.control from both org.scala.lang.scala3.library and scala.library
error: module scala.library reads package scala.runtime from both org.scala.lang.scala3.library and scala.library
error: module scala.library reads package scala.reflect from both org.scala.lang.scala3.library and scala.library
error: module scala.library reads package scala.annotation from both org.scala.lang.scala3.library and scala.library
error: module org.scala.lang.scala3.library reads package scala from both scala.library and org.scala.lang.scala3.library
error: module org.scala.lang.scala3.library reads package scala.util from both scala.library and org.scala.lang.scala3.library
error: module org.scala.lang.scala3.library reads package scala.util.control from both scala.library and org.scala.lang.scala3.library
error: module org.scala.lang.scala3.library reads package scala.runtime from both scala.library and org.scala.lang.scala3.library
error: module org.scala.lang.scala3.library reads package scala.reflect from both scala.library and org.scala.lang.scala3.library
error: module org.scala.lang.scala3.library reads package scala.annotation from both scala.library and org.scala.lang.scala3.library
/home/flo/repos/beanstalk/beanstalk-core/src/main/java/module-info.java:1: error: module eu.geekplace.beanstalk.core reads package scala from both org.scala.lang.scala3.library and scala.library
module eu.geekplace.beanstalk.core {
^
19 errors
I assume that is because the scala package is provided by multiple modules: scala3-library and scala-library (upon which scala3-library depends). I guess I have to wait till
is fixed? Or are there other ways to get my build going?
will “patch” the contents of scala-library in the org.scala.lang.scala3.library module, which scala3-library declares, and thus resolve the split package situation.
But thanks for pointing me into the right direction!