Test in Eclipse works but sbt throws MissingRequirementError: object scala.runtime in compiler mirror not found

前端 未结 2 1473
长情又很酷
长情又很酷 2021-01-21 11:10

I am messing around with parsing and scala.tools.nsc.interactive.Global in Scala and I ran into a problem while executing tests under sbt. The tests run fine from E

相关标签:
2条回答
  • 2021-01-21 11:40

    It looks like the scala jar isn't in your classpath when running sbt - make sure to add scala-library.jar to your classpath before you run sbt.


    Based on one of your comments, it looks like you're running on windows. you might be also running into runtime jar access errors there if the classpath contains strange characters or spaces, or permission errors (e.g., if eclipse is running under an admin account, while sbt isn't).


    Try reordering your dependency list, to put scala-library ahead of scala-compiler. if that doesn't work, try the troubleshooting advice here.

    0 讨论(0)
  • 2021-01-21 11:45

    The scala-library.jar was not missing from the sbt's classpath but from the classpath of Global. Had to set it in code.

    After modifying the source to

    val settings = new Settings
    
    val scalaLibraryPath = "/home/csajka/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.10.3.jar"
    settings.bootclasspath.append(scalaLibraryPath)
    settings.classpath.append(scalaLibraryPath)
    
    val reporter = new ConsoleReporter(settings)
    val global = new Global(settings, reporter, "Study compile")
    

    the problem disappeared.

    Thanks for the tip @blueberryfields!

    0 讨论(0)
提交回复
热议问题