I'm just trying to execute a simple Hello World application in Scala on Intellij with SBT but even this... it seem to be way too tough.
I followed the instructions here : https://www.cloudera.com/tutorials/setting-up-a-spark-development-environment-with-scala/.html
I use to work with Eclipse and Maven... Here I'm on Intellij and SBT so I try my best but I'm a bit lost. Here is what I've done :
- I installed Intellij, SBT.
- I configured SBT launcher in Intellij by setting File > Settings > Build, Execution, Deployment > Build tools > sbt > Launcher
- Create new Project with Java 1.8, SBT 1.3, Scala 2.13
- At this step I couldn't create Scala class, but I noted that if i "Reimport sbt project" then the scala class will appear in the list of new element to create.
- Create an object with main method :
object HelloScala {
def main(args: Array[String]): Unit = {
println("Hello world!")
}
}
When I try to execute that main it result in the following error :
Error:scalac: Multiple 'scala-library*.jar' files (scala-library-2.13.0.jar, scala-library-2.13.0.jar) in Scala compiler classpath in Scala SDK sbt: org.scala-lang:scala-library:2.13.0:jar
My build.sbt :
name := "HelloScala"
version := "0.1"
scalaVersion := "2.13.0"
I checked the Compiler classpath in File > Project Structure > Libraries > Compiler classpath :
file:///AppData/Local/Coursier/cache/v1/https/repo1.maven.org/maven2/jline/jline/2.14.6/jline-2.14.6.jar
file:///AppData/Local/Coursier/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.13.0/scala-compiler-2.13.0.jar
file:///AppData/Local/Coursier/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.0/scala-library-2.13.0.jar
file:///AppData/Local/Coursier/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.13.0/scala-reflect-2.13.0.jar
I tried to delete target directory, invalidate cache, regenerate the .idea folder by deleting it and let intellij recreate it, I searched from other scala-library.jar in the project structure. I've found nothing...
Really... I don't understand why the scala-library is referenced twice.
If I change the scala version from 2.13.0 to 2.11.0, same problem :
Error:scalac: Multiple 'scala-library*.jar' files (scala-library-2.11.0.jar, scala-library-2.11.0.jar) in Scala compiler classpath in Scala SDK sbt: org.scala-lang:scala-library:2.11.0:jar
BUT ! If I comment the scala version in the build.sbt :
name := "HelloScala"
version := "0.1"
//scalaVersion := "2.11.0"
Then if I clear the target directory, reimport sbt project and try to execute, it works! And in the target directory, I've a new scala-2.12 folder... Where the hell it come from?!
For information, I'm on Windows 10, Intellij 2019.2, JDK 1.8, SBT 13
Any help is really appreciated!
compile
,run
instead of Ctrl+Shift+F9/Ctrl+Shift+F10? (When you import a project to IntelliJ there are checkboxes "Use sbt shell: for imports, for builds", this redirects Ctrl+Shift+F9/Ctrl+Shift+F10 to sbt shell.) – Dmytro Mitin