sbt的第一步

时间:2015-11-18 14:53:00

标签: jvm sbt startup scalac

我只是想在scalac <some file>run <some class>循环中避免慢速JVM启动和清理。也就是说,我要求一个可以加载一次的环境,然后多次编译和运行我的应用程序。在#scala频道,我建议使用sbt

我曾经在#progfun课程中使用过现成的sbt脚本,但从未对自己编程过sbt。它看起来像个地狱。你如何轻松地为我的任务配置它?

1 个答案:

答案 0 :(得分:1)

% 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"

如果您愿意,可以使用setsession save添加更多设置,也可以直接修改文件。

如果你没有明确地设置scalaVersion,遗憾的是你会得到Scala 2.10而不是2.11: - (