Sbt
SBT는 최신 빌드 도구 중 하나이다. 스칼라로 작성되었고, 스칼라에 사용하기 편한 기능을 많이 제공하기는 하지만, SBT 자체는 범용 빌드 도구이다.
Categories
- java
- sbt:Basic - sbt 기초
- sbt:Example:StartupScript - sbt 시작을 위한 bash 스크립트.
- com.typesafe.config.ConfigFactory
SBT를 쓰는 이유는?
- 의존성 관리
- 의존성 관리에 Ivy를 사용
- 요청이 올때만 업데이트(Only-update-on-request) 모델
Commands
-
sonatypeList: List staging repositories -
sonatypeOpen: Create a staging repository and set publishTo -
sonatypeClose: Close a stage and clear publishTo if it was set by sonatypeOpen -
sonatypePromote: Promote a staged repository -
sonatypeDrop: Drop a staging repository -
sonatypeRelease: Publish with sonatypeClose and sonatypePromote -
sonatypeReleaseAll: Publish all staging repositories to Maven central -
sonatypeLog: Show repository activities -
coverage: ';set coverageEnabled in ThisBuild := true' -
coverageOn: ';set coverageEnabled in ThisBuild := true' -
coverageOff: ';set coverageEnabled in ThisBuild := false' -
publishC: ';reload;clean;assembly;publish' -
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 providedproject. -
set [every]<setting>: Evaluates a Setting and applies it to the current project. -
session: Manipulates session settings.</code>: 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'.</code>: Valid levels: debug, info, warn, error
-
plugins: Lists currently available plugins. -
--addPluginSbtFile=<file>: Adds the given *.sbt file to the plugin build. -
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'. -
lastGrep: 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'. - <code>all<task>
+</code>: 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, java+, java++, onFailure, reboot, shell, startServer
Tasks
This is a list of tasks defined for the current project. It does not list the scopes the tasks are defined in; use the 'inspect' command for that. Tasks produce values. Use the 'show' command to run the task and print the resulting value.
-
bgRun: Start an application's default main class as a background job -
bgRunMain: Start a provided main class as a background job -
checkPgpSignatures: Checks the signatures of artifacts to see if they are trusted. -
clean: Deletes files produced by the build, such as generated sources, compiled classes, and task caches. -
compile: Compiles sources. -
console: Starts the Scala interpreter with the project classes on the classpath. -
consoleProject: Starts the Scala interpreter with the sbt and the build definition on the classpath and useful imports. -
consoleQuick: Starts the Scala interpreter with the project dependencies on the classpath. -
copyResources: Copies resources to the output directory. -
doc: Generates API documentation. -
fgRun: Start an application's default main class as a foreground job -
fgRunMain: Start a provided main class as a foreground job -
packInstall: pack and install -
package: Produces the main artifact, such as a binary jar.</code>: This is typically an alias for the task that actually does the packaging. -
packageBin: Produces a main artifact, such as a binary jar. -
packageDoc: Produces a documentation artifact, such as a jar containing API documentation. -
packageSrc: Produces a source artifact, such as a jar containing sources and resources. -
publish: Publishes artifacts to a repository. -
publishDoc: Publish doc -
publishLocal: Publishes artifacts to the local Ivy repository. -
publishLocalSigned: Publishing all artifacts to a local repository, but SIGNED using PGP. -
publishM2: Publishes artifacts to the local Maven repository. -
publishSigned: Publishing all artifacts, but SIGNED using PGP. -
publishTM: Publish jar -
run: Runs a main class, passing along arguments provided on the command line. -
runMain: Runs the main class selected by the first argument, passing the remaining arguments to the main method. -
test: Executes all tests. -
testOnly: Executes the tests provided as arguments or all tests if no arguments are provided. -
testQuick: Executes the tests that either failed before, were not run or whose transitive dependencies changed, among those provided as arguments. -
update: Resolves and optionally retrieves dependencies, producing a report.
More tasks may be viewed by increasing verbosity. See 'help tasks'
시작하기
아래 예와 같이 다운로드 받은 jar를 호출하는 셀 스크립트를 작성하라.
앞에서 만든 스크립트가 실행 경로에 포함되어 있는지 확인하라. sbt를 실행해 프로젝트를 시작하라.
프로젝트가 없다면 다음과 같이 새로운 프로젝트를 생성한다.
[local ~/projects]$ sbt
Project does not exist, create new project? (y/N/s) y
Name: sample
Organization: com.twitter
Version [1.0]: 1.0-SNAPSHOT
Scala version [2.7.7]: 2.8.1
sbt version [0.7.4]:
Getting Scala 2.7.7 ...
:: retrieving :: org.scala-tools.sbt#boot-scala
confs: [default]
2 artifacts copied, 0 already retrieved (9911kB/221ms)
Getting org.scala-tools.sbt sbt_2.7.7 0.7.4 ...
:: retrieving :: org.scala-tools.sbt#boot-app
confs: [default]
15 artifacts copied, 0 already retrieved (4096kB/167ms)
[success] Successfully initialized directory structure.
Getting Scala 2.8.1 ...
:: retrieving :: org.scala-tools.sbt#boot-scala
confs: [default]
2 artifacts copied, 0 already retrieved (15118kB/386ms)
[info] Building project sample 1.0-SNAPSHOT against Scala 2.8.1
[info] using sbt.DefaultProject with sbt 0.7.4 and Scala 2.7.7
항상 프로젝트 시작시에는 SNAPSHOT 버전을 가지고 시작하라.
프로젝트 구조
- project – 프로젝트 정의 파일들
- project/build/.scala – 주 프로젝트 정의 파일
- project/build.properties – 프로젝트, sbt, 스칼라 버전 정의
sbt shell command
-
compile: 컴파일한다. -
~compile: 코드에 변경사항이 발생될 경우 자동으로 컴파일 한다. (켜놓고 코딩하면 될듯) -
run: 실행한다.
See also
Favorite site
Documentation
Tutorials
References
-
Scala_School_-Build_Tool-_SBT.pdf ↩