% mkdir myproj
% cd myproj
% echo 'object MyProject extends App { println("hello world") }' > MyProject.scala
% sbt
[info] Loading global plugins from /Users/tisue/.sbt/0.13/plugins
[info] Set current project to myproj (in build file:/Users/tisue/myproj/)
> set scalaVersion := "2.11.7"
[info] Defining *:scalaVersion
[info] The new value will be used by *:Additional arguments for the presentation compiler., *:allDependencies and 13 others.
[info] Run `last` for details.
[info] Reapplying settings...
[info] Set current project to myproj (in build file:/Users/tisue/myproj/)
> session save
[info] Reapplying settings...
[info] Set current project to myproj (in build file:/Users/tisue/myproj/)
> run
[info] Updating {file:/Users/tisue/myproj/}myproj...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/tisue/myproj/target/scala-2.11/classes...
[info] Running MyProject
hello world
[success] Total time: 2 s, completed Nov 18, 2015 9:46:26 PM
>
, если вы хотите, вы можете поместить свои источники под src/main/scala
, а не на уровне корневой директории проекта - что тоже работает.
session save
создает build.sbt
файл, который выглядит следующим образом:
scalaVersion := "2.11.7"
вы можете добавить дополнительные параметры там позже, если вам нравится, либо с set
и session save
, или путем редактирования файла непосредственно.
, если вы не установили scalaVersion
явно, к сожалению, вы получите Scala 2.10 вместо 2.11 :-(
хороший блог на это http://tpolecat.github.io/2014/12/ 12/get-started.html –
Удивительно, но мы нигде не указали основной класс. Я обнаружил, что 'run-main MyProject' делает трюк, и я думаю, что стоит быть частью' Getting Started'. –
У меня было использовать 'set includeFilter in (Compile, unmanagedSources): =" * .scala "||" * .sc ", чтобы включить файлы рабочих таблиц в компиляцию. –