42

I have openjdk, scala and sbt, all installed via brew. I'm trying to get setup to work on the scala track on exercism. I'm having no troubles with Java or anything that uses the JVM like clojure, but when I try to test my installation of scala by running the test for the exercism hello example:

$ sbt test

I get a bunch of errors that seem to start with this:

java.io.IOError: java.lang.RuntimeException: /packages cannot be represented as URI

My installed versions are as follows:

$ java --version
openjdk 13.0.1 2019-10-15
OpenJDK Runtime Environment AdoptOpenJDK (build 13.0.1+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 13.0.1+9, mixed mode, sharing)

$ scala -version
Scala code runner version 2.13.1 -- 

$ sbt --version
sbt version in this project: 1.3.8
sbt script version: 1.3.8

I've looked and seen this error in a few questions but not seen a way to fix it.

0mcg0
  • 431
  • 1
  • 4
  • 4
  • Can you share some code to reproduce the problem? – Luis Miguel Mejía Suárez Feb 19 '20 at 19:57
  • 1
    The problem is not with the code, it's with the tooling. The code is from https://exercism.io/my/tracks/scala, the hello project. The code compiles, it's a java runtime error. – 0mcg0 Feb 19 '20 at 20:02
  • given `sbt test` I supposed a project, I do not know what does it mean to run it outside of any project, but I guess it shouldn't throw that exception. Does the same happens if you run the **repl** with the `scala` command? If so, I would guess the problem is your JDK version, but according to [this](https://docs.scala-lang.org/overviews/jdk-compatibility/overview.html#jdk-13-and-14-compatibility-notes) it should just work. – Luis Miguel Mejía Suárez Feb 19 '20 at 20:07
  • 3
    Related issue: https://github.com/sbt/sbt/issues/5093. It's a long thread, the first things to check would be if you're specifying different Scala and/or SBT version in build.sbt or project/build.properties? – Pasi Feb 19 '20 at 20:08
  • Exercism is providing a project.sbt with an older version of scala listed. I fixed this and no longer get -that- error. So this is fixed. – 0mcg0 Feb 19 '20 at 20:34
  • Any update on this? Faced some issue, it really depends on environment – GoodPerson Mar 26 '20 at 15:58
  • I also fixed this problem by editing the build.sbt file – Stefan Papp Apr 04 '20 at 11:52
  • 2
    I had the same issue with using mill and Scala 2.12.4. Just upgrading Scala to 2.13.1 fixed it. I'm using openjdk 14 2020-03-17 – stondo Apr 09 '20 at 15:13
  • Not sure how or why, but upgrading sbt to 1.4.5 fixed this error for me on Java 15. – Gaurav Dec 17 '20 at 19:08

9 Answers9

60

I solved the issue by installing a java version of 1.8 and set JAVA_HOME towards this version.

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home"

XWZ
  • 743
  • 5
  • 7
11

I've got the same issue on IntelliJ IDEA and solved it with

Settings > Build, Exec... > Build Tools > sbt > JRE > set to 1.8.

JAVA_HOME has not resolve it in my case

Syscall
  • 19,327
  • 10
  • 37
  • 52
pin
  • 111
  • 1
  • 2
5

In my case, in Intellij IDEA, I had JAVA_HOME as well as sbt JRE from the previous answer set to 1.8, but I completely forgot about the Project SDK, which was set to an incompatible version.

Ctrl + Alt + Shift + S > Project Settings > Project > Project SDK

Setting this to 1.8 as well as language levels of modules to 8 fixed my issues.

4

Intellij :

open Settings -> Build, Execution, Deployment -> Scala Compiler -> Scala Compile Server, then change the JDK to the one your project used. This solution solved my problem.

Ram Ghadiyaram
  • 28,239
  • 13
  • 95
  • 121
1

What helped me here was:

File > Settings > Build, Execution, Deployment > Compiler > Scala Compile Server

Beside JDK, I set it to 1.8, built the application, issue was resolved.

0

IntelliJ:

  • Go to File -> Settings -> Build, Execution, Deployment -> Build Tools -> sbt
  • Make sure Use sbt shell for build is checked
Jirayu S
  • 301
  • 2
  • 4
0

I found this S/O answer solves my issue:

This is a Scala compiler bug. Please upgrade to the latest Scala point release, 2.12.16.

Thammarith
  • 662
  • 5
  • 19
0

Settings -> Build, Execution, Deployment -> Scala Compiler -> Scala Compile Server work for me

zcenao21
  • 1
  • 1
0

In my case, it is related to Intellij's Scala compile server settings.

go to settings -> Build, Exec... -> Compiler -> Scala Compile Server

uncheck use compile server

this solved the issue for me