[컴] sbt 사용

 scala  / build system

sbt 사용

ref. 1 내용을 일부 정리했다. 자세한 내용은 아래 링크의 내용을 확인하자.

sbt 설치

  • sdkman: https://sdkman.io/install
  • sbt install : https://www.scala-sbt.org/1.x/docs/Installing-sbt-on-Linux.html
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install java $(sdk list java | grep -o "8\.[0-9]*\.[0-9]*\.hs-adpt" | head -1)
sdk install sbt

sbt 로 project 생성

  1. project directory 생성 및 이동
  2. build.sbt 생성
  3. sbt 실행 --> exit : prject, target 폴더가 만들어진다.
  4. example package 생성
    • <proj_root>\src\main\scala\example\ directory 생성
  5. library 추가

mkdir kbdumpna
cd kbdumpna
touch build.sbt

sbt
sbt> scalaVersion
sbt> set ThisBuild / scalaVersion := "2.12.12"

sbt> reload
sbt> test

sbt> compile
sbt> run


sbt> reload
sbt> compile

template 에서 project 시작하기

boilerplate 에서 시작할 수 있다. 아래처럼 sbt new 를 사용하자.

  • sbt new akka/akka-scala-seed.g8
Microsoft Windows [Version 10.0.19041.450]
(c) 2020 Microsoft Corporation. All rights reserved.

D:\a\prog\scala\akka\simple-chat>sbt new akka/akka-scala-seed.g8
[info] [launcher] getting org.scala-sbt sbt 1.3.13  (this may take some time)...
downloading https://repo1.maven.org/maven2/org/scala-sbt/main_2.12/1.3.13/main_2.12-1.3.13.jar ...
...
[info] resolving Giter8 0.13.1...

Akka is a toolkit and runtime for building highly concurrent,
distributed, and fault tolerant event-driven apps. This simple
application will get you started building Actor based systems with
Scala. This app uses Akka, Scala, and ScalaTest.

name [akka-quickstart-scala]: simple-chat
akka_version [2.6.8]: 
package [com.example]: com.schat

Template applied in D:\a\prog\scala\akka\simple-chat\.\simple-chat 

sbt interactive shell 에서 명령어

sbt compile처럼 사용할 수도 있고, 또는 sbt 를 실행한 이후에 intereactive shell 에서 compile 명령어를 상요할 수도 있다.

  1. compile
    • compile
    • ~compile 는 watch 와 같다. code 가 변경되면 알아서 compile 하도록 할 수 있다.
  2. 실행
    • run
  3. 변수 정의
    • set ThisBuild / scalaVersion := "2.12.7"
  4. session save
    • sbt interactive shell 에서 정의한 변수들을 session save 명령어를 이용해서 build.sbt 에 저장해 놓을 수 있다.
  5. build.sbt 가 변경된 이후 내용을 reload
    • reload

주의할점

ref.1 에서는 build.sbtThisBuild / scalaVersion := "2.12.7" 라고 적었는데,

sbt 1.3.13 (Oracle Corporation Java 14) 에서 2.12.7 은 아래 이슈가 발생했다. 그래서 2.12.10 을 사용했다.

C:\a\prog\scala\nchat>md nchat
C:\a\prog\scala\nchat>cd nchat

build.sbt 생성


C:\a\prog\scala\nchat>sbt
[warn] Neither build.sbt nor a 'project' directory in the current directory: "C:\a\prog\scala\nchat"
c) continue
q) quit
?c
[info] [launcher] getting org.scala-sbt sbt 1.3.13  (this may take some time)...
downloading https://repo1.maven.org/maven2/org/scala-sbt/main-settings_2.12/1.3.13/main-settings_2.12-1.3.13.jar ...
downloading https://repo1.maven.org/maven2/org/scala-sbt/actions_2.12/1.3.13/actions_2.12-1.3.13.jar ...
downloading https://repo1.maven.org/maven2/org/scala-sbt/run_2.12/1.3.13/run_2.12-1.3.13.jar ...
downloading https://repo1.maven.org/maven2/org/scala-sbt/logic_2.12/1.3.13/logic_2.12-1.3.13.jar ...
downloading https://repo1.maven.org/maven2/org/scala-sbt/main_2.12/1.3.13/main_2.12-1.3.13.jar ...
downloading https://repo1.maven.org/maven2/org/scala-sbt/sbt/1.3.13/sbt-1.3.13.jar ...
:: loading settings :: url = jar:file:/C:/Program%20Files%20(x86)/sbt/bin/sbt-launch.jar!/org/apache/ivy/core/settings/ivysettings.xml
:: loading settings :: url = jar:file:/C:/Program%20Files%20(x86)/sbt/bin/sbt-launch.jar!/org/apache/ivy/core/settings/ivysettings.xml
:: loading settings :: url = jar:file:/C:/Program%20Files%20(x86)/sbt/bin/sbt-launch.jar!/org/apache/ivy/core/settings/ivysettings.xml
:: loading settings :: url = jar:file:/C:/Program%20Files%20(x86)/sbt/bin/sbt-launch.jar!/org/apache/ivy/core/settings/ivysettings.xml
:: loading settings :: url = jar:file:/C:/Program%20Files%20(x86)/sbt/bin/sbt-launch.jar!/org/apache/ivy/core/settings/ivysettings.xml
:: loading settings :: url = jar:file:/C:/Program%20Files%20(x86)/sbt/bin/sbt-launch.jar!/org/apache/ivy/core/settings/ivysettings.xml
:: loading settings :: url = jar:file:/C:/Program%20Files%20(x86)/sbt/bin/sbt-launch.jar!/org/apache/ivy/core/settings/ivysettings.xml
:: loading settings :: url = jar:file:/C:/Program%20Files%20(x86)/sbt/bin/sbt-launch.jar!/org/apache/ivy/core/settings/ivysettings.xml
downloading https://repo1.maven.org/maven2/org/scala-sbt/command_2.12/1.3.13/command_2.12-1.3.13.jar ...
downloading https://repo1.maven.org/maven2/org/scala-sbt/collections_2.12/1.3.13/collections_2.12-1.3.13.jar ...
        [SUCCESSFUL ] org.scala-sbt#sbt;1.3.13!sbt.jar (1202ms)
downloading https://repo1.maven.org/maven2/org/scala-sbt/scripted-sbt-redux_2.12/1.3.13/scripted-sbt-redux_2.12-1.3.13.jar ...
        [SUCCESSFUL ] org.scala-sbt#run_2.12;1.3.13!run_2.12.jar (1238ms)
downloading https://repo1.maven.org/maven2/org/scala-sbt/scripted-plugin_2.12/1.3.13/scripted-plugin_2.12-1.3.13.jar ...
        [SUCCESSFUL ] org.scala-sbt#logic_2.12;1.3.13!logic_2.12.jar (1339ms)
downloading https://repo1.maven.org/maven2/org/scala-sbt/zinc-lm-integration_2.12/1.3.13/zinc-lm-integration_2.12-1.3.13.jar ...
        [SUCCESSFUL ] org.scala-sbt#command_2.12;1.3.13!command_2.12.jar (1500ms)
downloading https://repo1.maven.org/maven2/org/scala-lang/modules/scala-xml_2.12/1.3.0/scala-xml_2.12-1.3.0.jar ...
        [SUCCESSFUL ] org.scala-sbt#actions_2.12;1.3.13!actions_2.12.jar (1685ms)
downloading https://repo1.maven.org/maven2/org/scala-sbt/launcher-interface/1.1.4/launcher-interface-1.1.4.jar ...
        [SUCCESSFUL ] org.scala-sbt#collections_2.12;1.3.13!collections_2.12.jar (1696ms)
downloading https://repo1.maven.org/maven2/io/get-coursier/lm-coursier-shaded_2.12/2.0.0-RC6-4/lm-coursier-shaded_2.12-2.0.0-RC6-4.jar ...
        [SUCCESSFUL ] org.scala-sbt#scripted-plugin_2.12;1.3.13!scripted-plugin_2.12.jar (561ms)
downloading https://repo1.maven.org/maven2/org/scala-sbt/librarymanagement-core_2.12/1.3.4/librarymanagement-core_2.12-1.3.4.jar ...
        [SUCCESSFUL ] org.scala-sbt#zinc-lm-integration_2.12;1.3.13!zinc-lm-integration_2.12.jar (695ms)
downloading https://repo1.maven.org/maven2/org/scala-sbt/librarymanagement-ivy_2.12/1.3.4/librarymanagement-ivy_2.12-1.3.4.jar ...
        [SUCCESSFUL ] org.scala-sbt#scripted-sbt-redux_2.12;1.3.13!scripted-sbt-redux_2.12.jar (921ms)
downloading https://repo1.maven.org/maven2/org/scala-sbt/completion_2.12/1.3.13/completion_2.12-1.3.13.jar ...
        [SUCCESSFUL ] org.scala-sbt#main_2.12;1.3.13!main_2.12.jar (2188ms)
downloading https://repo1.maven.org/maven2/org/scala-sbt/task-system_2.12/1.3.13/task-system_2.12-1.3.13.jar ...
        [SUCCESSFUL ] org.scala-sbt#launcher-interface;1.1.4!launcher-interface.jar (676ms)
downloading https://repo1.maven.org/maven2/org/scala-sbt/tasks_2.12/1.3.13/tasks_2.12-1.3.13.jar ...
        [SUCCESSFUL ] org.scala-lang.modules#scala-xml_2.12;1.3.0!scala-xml_2.12.jar(bundle) (873ms)
downloading https://repo1.maven.org/maven2/org/scala-sbt/testing_2.12/1.3.13/testing_2.12-1.3.13.jar ...
        [SUCCESSFUL ] org.scala-sbt#task-system_2.12;1.3.13!task-system_2.12.jar (574ms)
downloading https://repo1.maven.org/maven2/org/scala-sbt/test-agent/1.3.13/test-agent-1.3.13.jar ...
        [SUCCESSFUL ] org.scala-sbt#librarymanagement-core_2.12;1.3.4!librarymanagement-core_2.12.jar (1343ms)
        [SUCCESSFUL ] org.scala-sbt#testing_2.12;1.3.13!testing_2.12.jar (764ms)
downloading https://repo1.maven.org/maven2/org/scala-sbt/protocol_2.12/1.3.13/protocol_2.12-1.3.13.jar ...
downloading https://repo1.maven.org/maven2/org/scala-sbt/core-macros_2.12/1.3.13/core-macros_2.12-1.3.13.jar ...
        [SUCCESSFUL ] org.scala-sbt#completion_2.12;1.3.13!completion_2.12.jar (1142ms)
downloading https://repo1.maven.org/maven2/org/scala-sbt/ivy/ivy/2.3.0-sbt-839fad1cdc07cf6fc81364d74c323867230432ad/ivy-2.3.0-sbt-839fad1cdc07cf6fc81364d74c323867230432ad.jar ...
        [SUCCESSFUL ] org.scala-sbt#test-agent;1.3.13!test-agent.jar (577ms)
        [SUCCESSFUL ] org.scala-sbt#tasks_2.12;1.3.13!tasks_2.12.jar (1038ms)
        [SUCCESSFUL ] org.scala-sbt#librarymanagement-ivy_2.12;1.3.4!librarymanagement-ivy_2.12.jar (1558ms)
        [SUCCESSFUL ] org.scala-sbt#core-macros_2.12;1.3.13!core-macros_2.12.jar (604ms)
        [SUCCESSFUL ] org.scala-sbt#protocol_2.12;1.3.13!protocol_2.12.jar (730ms)
        [SUCCESSFUL ] io.get-coursier#lm-coursier-shaded_2.12;2.0.0-RC6-4!lm-coursier-shaded_2.12.jar (2933ms)
        [SUCCESSFUL ] org.scala-sbt#main-settings_2.12;1.3.13!main-settings_2.12.jar (6066ms)
        [SUCCESSFUL ] org.scala-sbt.ivy#ivy;2.3.0-sbt-839fad1cdc07cf6fc81364d74c323867230432ad!ivy.jar (3345ms)
:: retrieving :: org.scala-sbt#boot-app
        confs: [default]
        81 artifacts copied, 0 already retrieved
[warn] No sbt.version set in project/build.properties, base directory: C:\a\prog\scala\nchat
[info] welcome to sbt 1.3.13 (Oracle Corporation Java 14)
[info] set current project to nchat (in build file:/C:/a/prog/scala/nchat/)
[info] sbt server started at local:sbt-server-251924dafe1d3bf2356b
sbt:nchat> exit
[info] shutting down sbt server
sbt:Hello> about
[info] This is sbt 1.3.13
[info] The current project is ProjectRef(uri("file:/C:/a/prog/scala/test2/"), "hello") 0.1.0-SNAPSHOT
[info] The current project is built against Scala 2.12.10
[info] Available Plugins
[info]  - sbt.ScriptedPlugin
[info]  - sbt.plugins.CorePlugin
[info]  - sbt.plugins.Giter8TemplatePlugin
[info]  - sbt.plugins.IvyPlugin
[info]  - sbt.plugins.JUnitXmlReportPlugin
[info]  - sbt.plugins.JvmPlugin
[info]  - sbt.plugins.SbtPlugin
[info]  - sbt.plugins.SemanticdbPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.12.10
sbt:Hello>   

Scala REPL

sbt:Hello> console
[info] Starting scala interpreter...
Welcome to Scala 2.12.10 (OpenJDK 64-Bit Server VM, Java 14).
Type in expressions for evaluation. Or try :help.

scala> println("test")
test

scala> :q

[success] Total time: 444 s (07:24), completed 2020. 8. 14. ?ㅼ쟾 11:31:366
sbt:Hello>

Reference

  1. sbt Reference Manual — Getting Started with sbt

댓글 없음:

댓글 쓰기