Skip to content

Java 9 "object scala in compiler mirror not found" #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
NersesAM opened this issue Feb 28, 2018 · 13 comments
Closed

Java 9 "object scala in compiler mirror not found" #234

NersesAM opened this issue Feb 28, 2018 · 13 comments

Comments

@NersesAM
Copy link

NersesAM commented Feb 28, 2018

Hi,

I am trying to upgrade my project to Java 9 but scala-maven-plugin fails. Same project runs fine on Java 8.

[DEBUG] plugin jar to add :/Users/Nerses/.m2/repository/net/alchim31/maven/scala-maven-plugin/3.3.1/scala-maven-plugin-3.3.1.jar
[DEBUG] cmd:  /Library/Java/JavaVirtualMachines/jdk-9.0.4.jdk/Contents/Home/bin/java -Xbootclasspath/a:/Users/Nerses/.m2/repository/org/scala-lang/scala-library/2.12.4/scala-library-2.12.4.jar:/Users/Nerses/.m2/repository/org/scala-lang/scala-compiler/2.12.4/scala-compiler-2.12.4.jar:/Users/Nerses/.m2/repository/org/scala-lang/modules/scala-xml_2.12/1.0.6/scala-xml_2.12-1.0.6.jar:/Users/Nerses/.m2/repository/org/scala-lang/scala-library/2.12.0/scala-library-2.12.0.jar:/Users/Nerses/.m2/repository/org/scala-lang/scala-reflect/2.12.4/scala-reflect-2.12.4.jar -classpath /Users/Nerses/.m2/repository/net/alchim31/maven/scala-maven-plugin/3.3.1/scala-maven-plugin-3.3.1.jar scala_maven_executions.MainWithArgsInFile scala.tools.nsc.Main /private/var/folders/tf/grzpgmz11r32d9dtvclkr1zx9sz3ys/T/scala-maven-15243357590113591240.args
[ERROR] error: error while loading Object, Missing dependency 'object scala in compiler mirror', required by /modules/java.base/java/lang/Object.class
[ERROR] error: scala.reflect.internal.MissingRequirementError: object scala in compiler mirror not found.
[ERROR]         at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:17)
[ERROR]         at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:18)
[ERROR]         at scala.reflect.internal.Mirrors$RootsBase.$anonfun$getModuleOrClass$4(Mirrors.scala:54)
[ERROR]         at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:54)
[ERROR]         at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:66)
[ERROR]         at scala.reflect.internal.Mirrors$RootsBase.getPackage(Mirrors.scala:172)
[ERROR]         at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackage$lzycompute(Definitions.scala:169)
[ERROR]         at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackage(Definitions.scala:169)
[ERROR]         at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackageClass$lzycompute(Definitions.scala:170)
[ERROR]         at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackageClass(Definitions.scala:170)
[ERROR]         at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1423)
[ERROR]         at scala.tools.nsc.Global$Run.<init>(Global.scala:1164)
[ERROR]         at scala.tools.nsc.Driver.doCompile(Driver.scala:34)
[ERROR]         at scala.tools.nsc.MainClass.doCompile(Main.scala:24)
[ERROR]         at scala.tools.nsc.Driver.process(Driver.scala:55)
[ERROR]         at scala.tools.nsc.Driver.main(Driver.scala:68)
[ERROR]         at scala.tools.nsc.Main.main(Main.scala)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]         at java.base/java.lang.reflect.Method.invoke(Method.java:564)
[ERROR]         at scala_maven_executions.MainHelper.runMain(MainHelper.java:164)
[ERROR]         at scala_maven_executions.MainWithArgsInFile.main(MainWithArgsInFile.java:26)

Do you know what is going wrong here?
There was a similar issue in sbt and it was fixed in 0.13.17 scala/scala-xml#173

@SethTisue
Copy link

I think @retronym might be able to point you in the right direction

@retronym
Copy link

retronym commented Mar 1, 2018

Please try upgrading to the latest minor version of Scala in the series you are using.

http://docs.scala-lang.org/overviews/jdk-compatibility/overview.html

These versions of Scala have code to read class files for the Java Standard Library from the new jrt:// virtual filesystem. Older JDKs just expose them in $JAVA_HOME/lib/rt.jar.

@NersesAM
Copy link
Author

NersesAM commented Mar 1, 2018

I'm using 2.12.4

I've tried also setting <scalaVersion>${scala-library.version}</scalaVersion> configuration, but still getting same error

@retronym
Copy link

retronym commented Mar 2, 2018

I've just tried a minimal project and was able to compile and run on Java 9.

⚡ (java_use 9; java -version; mvn -q clean install; cd m2; mvn -q exec:java  -Dexec.mainClass="m2.M2")
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
Java HotSpot(TM) 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
/code/scala-maven-java9/m2
Java HotSpot(TM) 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
hello, Maven, Scala, Java 9
/code/scala-maven-java9
⚡

Could you try that project on your machine?

@davidB
Copy link
Owner

davidB commented Mar 2, 2018

From the initial log, I saw 2 version of scala-library 2.12.4 & 2.12.0 in bootclasspath.
Can you share the pom.xml ?

The injection of the second scala-library could be caused by a "compilerPlugins".

@NersesAM
Copy link
Author

NersesAM commented Mar 3, 2018

@retronym i tried your project and it works. Trying to see if i can reproduce, by adding more stuff to it from my project. Will report back if i can

@davidB I noticed that as well, no idea where 2.12.0 comes from. I don't think that's the problem though. When I take that cmd line from debug and run in the terminal after removing 2.12.0 form bootclasspath it still fails

@NersesAM
Copy link
Author

NersesAM commented Mar 3, 2018

@retronym @davidB I was able to reproduce it. https://github.com/NersesAM/scala-maven-java9

The problem seems to be because in that particular module I had code in Java, but tests were written in Scala. In that case /private/var/folders/tf/grzpgmz11r32d9dtvclkr1zx9sz3ys/T/scala-maven-15243357590113591240.args file doesn't contain scala-library in the classpath and build fails.

@adridadou
Copy link

that's exactly my use case. Hopefully this will be solved soon so I can still test my java code with some awesome scala !

@NersesAM
Copy link
Author

NersesAM commented Mar 7, 2018

@adridadou you can fix it by removing scala-compile-first execution and letting maven-compile-plugin to compile java files.
https://github.com/NersesAM/scala-maven-java9/blob/3a55caffa333b5c7de56e4376e4a24888f0a4add/pom.xml#L29-L36

@adridadou
Copy link

it worked! thank you very much!

@jrgleason
Copy link

Sorry to throw in a comment on such an old issue. I had a similar issue upgrading to Scala 2.13. However, when I remove the execution the Java code can no longer see the Scala code.

@slandelle
Copy link
Collaborator

@jrgleason Please open a new issue where you make sure to provide a sample project to reproduces your issue. Prior to that, please make that's not simply a matter of a broken maven download and the scala-library jar in your local maven cache is corrupted.

@jrgleason
Copy link

Ok will do thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants