Hello. I am at the beginning of my learning path in Scala (not new to programming though) and I am having troubles running and testing my code. I am following the Scala track in Exercism (Scala on Exercism) on my Mac with IntelliJ.
The exercises there come with a test (that is executed using sbt test
in the right directory) but some of the exercises have tests that don’t work, throwing the error /packages cannot be represented as URI
. I have googled it and after a few StackOverflow answers, I have not been able to run it without errors. The info about my Scala, Java and sbt installation is the following (all three have been installed using brew):
[info] [launcher] getting org.scala-sbt sbt 1.5.6 (this may take some time)...
WARNING: A terminally deprecated method in java.lang.System has been called
WARNING: System::setSecurityManager has been called by sbt.TrapExit$ (file:/Users/javier.lopez/.sbt/boot/scala-2.12.14/org.scala-sbt/sbt/1.5.6/run_2.12-1.5.6.jar)
WARNING: Please consider reporting this to the maintainers of sbt.TrapExit$
WARNING: System::setSecurityManager will be removed in a future release
sbt version in this project: 1.5.6
sbt script version: 1.5.6
Scala code runner version 2.13.7 -- Copyright 2002-2021, LAMP/EPFL and Lightbend, Inc.
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment (build 17.0.1+12-39)
OpenJDK 64-Bit Server VM (build 17.0.1+12-39, mixed mode, sharing)
“I will compile and run my code from IntelliJ”, I have thought, after giving up on the tests. But I am unable to do so either, because I have no run button anywhere. In my build configuration I have set either default JSDK or java 17.
I have tried also a couple of Run/Debug configurations, but I don’t think none of them is correct:
I have reinstalled as well the IDE. So, at this point, I thought, “OK, I will just execute the code myself from the terminal”. The code is the following (pretty simple):
object Bob extends App {
def response(statement: String): String = {
if (statement.takeRight(1) == "?") {
println("whoa")
"Whoa, chill out!"
}
else {
println("whatever")
"Whatever."
}
}
}
I have compiled it from the terminal with:
scalac Bob.scala
And then I have tried to run with several commands:
scala response
scala Bob.response
scala Bob.Bob.response
scala Bob.response “test sentence”
Getting either an error or nothing.
I am lost and I have no idea how to solve the situation. Any help would be appreciated.
Thank you very much