Tiven Wang
Wang Tiven May 09, 2018
425 favorite favorites
bookmark bookmark
share share

sbt 是一个代码构建工具,它支持 Scala Java 和其他多种语言。要求 Java 1.8 及以上版本的支持。

可以参考文档 Installing sbt 进行安装。

sbt 使用 build.sbt 作为一个项目的主配置文件。在项目文件夹下运行命令 sbt 进入交互模式即 sbt interactive shell。在 sbt shell 中可以运行各种命令, 使用 help 查看有哪些命令可以运行

[scala-starter-example] $ help

  about                                          Displays basic information about sbt and the build.
  tasks                                          Lists the tasks defined for the current project.
  settings                                       Lists the settings defined for the current project.
  reload                                         (Re)loads the current project or changes to plugins project or returns from it.
  new                                            Creates a new sbt build.
  projects                                       Lists the names of available projects or temporarily adds/removes extra builds to the session.
  project                                        Displays the current project or changes to the provided `project`.
  set [every] <setting>                          Evaluates a Setting and applies it to the current project.
  session                                        Manipulates session settings.  For details, run 'help session'.
  inspect [tree|uses|definitions|actual] <key>   Prints the value for 'key', the defining scope, delegates, related definitions, and dependencies.
  <log-level>                                    Sets the logging level to 'log-level'.  Valid levels: debug, info, warn, error
  plugins                                        Lists currently available plugins.
  last                                           Displays output from a previous command or the output from a specific task.
  last-grep                                      Shows lines from the last output for 'key' that match 'pattern'.
  export <tasks>+                                Executes tasks and displays the equivalent command lines.
  show <key>                                     Displays the result of evaluating the setting or task associated with 'key'.
  all <task>+                                    Executes all of the specified tasks concurrently.
  help                                           Displays this help message or prints detailed help on requested commands (run 'help <command>').
  completions                                    Displays a list of completions for the given argument string (run 'completions <string>').
  ; <command> (; <command>)*                     Runs the provided semicolon-separated commands.
  early(<command>)                               Schedules a command to run before other commands on startup.
  exit                                           Terminates the build.
  ~ <command>                                    Executes the specified command whenever source files change.

More command help available using 'help <command>' for:
  !, +, ++, +-, <, ^, ^^, alias, append, apply, client, eval, iflast, onFailure, reboot, shell, startServer

使用 exit 退出 sbt shell

Scala REPL

还可以从 sbt shell 进入 Scala REPL console 模式,使用 console 命令

[scala-starter-example] $ console
[info] Starting scala interpreter...
Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131).
Type in expressions for evaluation. Or try :help.

scala>

使用 :help 查看更多命令

scala> :help
All commands can be abbreviated, e.g., :he instead of :help.
:edit <id>|<line>        edit history
:help [command]          print this summary or command-specific help
:history [num]           show the history (optional num is commands to show)
:h? <string>             search the history
:imports [name name ...] show import history, identifying sources of names
:implicits [-v]          show the implicits in scope
:javap <path|class>      disassemble a file or class name
:line <id>|<line>        place line(s) at the end of history
:load <path>             interpret lines in a file
:paste [-raw] [path]     enter paste mode or paste a file
:power                   enable power user mode
:quit                    exit the interpreter
:replay [options]        reset the repl and replay all previous commands
:require <path>          add a jar to the classpath
:reset [options]         reset the repl to its initial state, forgetting all session entries
:save <path>             save replayable session to a file
:sh <command line>       run a shell command (result is implicitly => List[String])
:settings <options>      update compiler options, if possible; see reset
:silent                  disable/enable automatic printing of results
:type [-v] <expr>        display the type of an expression without evaluating it
:kind [-v] <type>        display the kind of a type. see also :help kind
:warnings                show the suppressed warnings from the most recent line which had any

在 Scala REPL console 可以交互式地执行 Scala 语言程序。

使用 :q 退出 Scala REPL console.

Dockerize your app

使用命令 Docker/publishLocal 把应用程序打包成本地的 Docker 镜像。

[scala-starter-example] $ Docker/publishLocal
...
[info] Successfully built 16769d5fc163
[info] Successfully tagged scala-starter-example:1.0-SNAPSHOT
[info] SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
[info] Built image scala-starter-example:1.0-SNAPSHOT
[success] Total time: 14 s, completed May 9, 2018 11:24:43 AM

然后便可运行应用程序的 Docker 容器

docker run scala-starter-example:1.0-SNAPSHOT

https://www.scala-sbt.org/

https://github.com/sbt/sbt

Proxy

set JAVA_OPTS=-Dhttp.proxySet=true -Dhttp.proxyHost=[Your Proxy server] -Dhttp.proxyPort=8080

https://www.scala-sbt.org/1.x/docs/Setup-Notes.html#HTTP%2FHTTPS%2FFTP+Proxy

https://stackoverflow.com/questions/13803459/how-to-use-sbt-from-behind-proxy

What’s Wrong with SBT

SBT 号称 Simple Build Tool 但实际上它什么都行,除了简单。查看这篇博客了解 SBT 有哪些问题 http://www.lihaoyi.com/post/SowhatswrongwithSBT.html

Similar Posts

Comments

Back to Top