Reputation:
I am beginner in Scala. I cant find how to add SBT Console. I have sbt shell, but in Scala course i see that they have both: SBT Shell and SBT Console, and using the second one. I tried to write "console" in sbt shell, and after "run", but it says:
error: not found: value run. So I just want to add somehow this SBT Console, to run my program not only from button "run" in Intellij.
And what about SBT? Is it really needed? Or can i dont use it for Scala?
Upvotes: 1
Views: 2203
Reputation: 26941
You're probably confused by "Shell" and "Console" usually being synonyms, but they actually mean different things with sbt.
sbt shell - is, uhm, a shell that sbt gives you when you run it in interactive mode - i.e. when you just run sbt
from your terminal. This gives you access to other exciting things, such as running the app (with run
command), inspecting the build (inspect ...
), running tests (test
, obviously) and so on.
sbt console - is an interactive REPL (read-evaluate-perform-loop) that gives you scala as an interpreter - i.e. you can type in (or paste) some scala code, and it will be immediately compiled and evaluated - outputting the results. Sbt console is also available from sbt shell - by running console
.
So, in order to run your program, you have two options (besides the IntelliJ "run" dialog):
sbt run
sbt
, then wait for sbt to initialize, then in the sbt shell do just run
.Refer to sbt docs for more details on different ways to run sbt (spoiler: there's also "batch" mode, where you can run sbt run
from your terminal - and it is exactly the same as sbt
and then run
).
Sbt Reference manual might also be helpful - specifically it covers the sbt console
command.
And what about SBT? Is it really needed? Or can i dont use it for Scala?
It is not mandatory - you can run scala with maven, it's just a bit more involved to configure. However, if you allow a bit of personal opinion, I'd recommend using sbt with scala projects (and even with Java projects). For one simple reason - the build definition in sbt is essentially just scala code - you can use any language features, third part libraries and even custom code in your build - which sometimes comes very helpful. Compared to maven, I think it's a big step forward, as in maven you define the build using a XML-based "language" defined by the mvn tool and it's plugins - which is much less customizable.
However, gradle
also has this advantage, so pick the tool that best suits your needs.
Upvotes: 2