rules_scala icon indicating copy to clipboard operation
rules_scala copied to clipboard

broken run with manifest jar

Open wisechengyi opened this issue 2 years ago • 1 comments

Repro'able for linux and mac.

The normal behavior is

% echo 3 | bazel run test:HelloLibRepl
...
INFO: Build completed successfully, 1 total action
Welcome to Scala 2.12.14 (OpenJDK 64-Bit Server VM, Java 11.0.15.0.9).
Type in expressions for evaluation. Or try :help.

scala> 3
res0: Int = 3

To repro the issue, we can set classpath limit to a small number to force the run script to run with the manifest jar, and we can clearly see that it's broken.

% echo 3 | bazel run test:HelloLibRepl -- --classpath_limit=5
...
-Dscala.usejavacp=true scala.tools.nsc.MainGenericRunner
Welcome to Scala 2.12.14 (OpenJDK 64-Bit Server VM, Java 11.0.15.0.9).
Type in expressions for evaluation. Or try :help.

scala> 3
[init] error: error while loading Object, Missing dependency 'object scala.native in compiler mirror', required by /modules/java.base/java/lang/Object.class

Failed to initialize compiler: object scala in compiler mirror not found.
** Note that as of 2.8 scala does not assume use of the java classpath.
** For the old behavior pass -usejavacp to scala, or if using a Settings
** object programmatically, settings.usejavacp.value = true.

Failed to initialize compiler: object scala in compiler mirror not found.
** Note that as of 2.8 scala does not assume use of the java classpath.
** For the old behavior pass -usejavacp to scala, or if using a Settings
** object programmatically, settings.usejavacp.value = true.
Interpreter encountered errors during initialization!
Exception in thread "Thread-1" java.lang.InterruptedException
	at java.base/java.util.concurrent.SynchronousQueue.put(SynchronousQueue.java:875)
	at scala.tools.nsc.interpreter.SplashLoop.run(Interact

Issue may be near https://github.com/bazelbuild/rules_scala/blob/f4a24fe2f76e1b1f2b24757f7740a2699692951f/java_stub_template/file/file.txt#L292-L339

wisechengyi avatar Sep 08 '22 18:09 wisechengyi

I am hitting this problem as well. But looks like with Java 9+ the problem can be solved with use_argument_file_in_runner = True when registering the scala toolchain.

Digging deeper it appears Scala is not able to load classpath from manfiest-only JARs. The usejavacp flag seems only honor classpath passed with -cp or through the args file. I suspect this is a limitation of Scala itself but I have not been able to find anything conclusive.

tgeng avatar Dec 21 '22 18:12 tgeng