Skip to content
AnArcher edited this page Dec 25, 2010 · 13 revisions

SBT 시작하기

SBT란?

  • SBT는 자바의 ant,maven처럼 빌드 도구입니다. ant나 maven이 xml으로 빌드 설정파일을 구성하는것에 반해 SBT는 스칼라 코드로 프로젝트나 플러그인 설정을 합니다.
  • http://code.google.com/p/simple-build-tool/

설치하기

 java -Xmx512M -jar `dirname $0`/sbt-launch.jar "$@"

SBT 프로젝트 시작하기

  • 특정 디렉토리에서 sbt을 실행하면 sbt는 프로젝트를 생성할것인지 물어봅니다.
sh>sbt
Project does not exist, create new project? (y/N/s) y
Name: testproject
Organization: codeport
Version [1.0]: 0.1
Scala version [2.7.7]: 2.8.1
sbt version [0.7.4]: 
Getting Scala 2.7.7 ...
...
  • 이렇게 생성되는 sbt는 설정에 관련된 파일(build.properties)을 하나만 만듭니다. sbt는 대개 설정에 관련된 파일이 3개정도 있는데요. 나머지 두개는 직접 만들어야 하더군요. (기본적으로 다 많을어주면 편할텐데욤.)
    
    

./project/build.properties ./project/build/Project.scala # 프로젝트 설정 ./project/plugins/Plugins.scala # sbt plugins 설정

  • 디렉토리 구조는 maven의 구조와 흡사합니다. (src/main/scala ... src/test/scala .. )

Project 설정하기

import sbt._

class Project(info:ProjectInfo) extends DefaultProject(info) {

    val casbah = "com.novus" % "casbah_2.8.0" % "1.0.8.5"   
    val bumnetworksRepo = "bumnetworks Repo" at "http://repo.bumnetworks.com/releases/"  

}
  • 딱보시면 아시겠지만 casbah는 라이브러리 설정리고 bumn..Repo는 레파지토리 설정입니다.
  • sbt는 디렉로리 구조를 보시면 아시겠지만. lib와 lib_managed으로 나누어져있습니다. 즉 lib_managed는 위와 같은 의존성 설정으로 관리되는 패캐지들이 존재하고 lib은 의존성 관리 없이 추가되는 라이브러리 공간입니다. (저는 이 구조가 마음에 들더군요. :-)
  • 이렇게 설정하고 sbt을 실행하면 설정이 변경되었다는 감지하여 update가 자동으로 이루어지지만 sbt 콘솔로 사용중일때에는 reload , update을 해야 됩니다.

플러그인 설정하기

  • 간단하게 IntelliJ 플러그인을 설정해 보겠습니다.
  • project/plugins/Plugins.scala
import sbt._
class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
  val sbtIdeaRepo = "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"
  val sbtIdea = "com.github.mpeltonen" % "sbt-idea-plugin" % "0.2.0"
}
  • project/build/Project.scala
class Project(info:ProjectInfo) extends DefaultProject(info) with IdeaProject {
...
}

bb:hellosbt anarcher$ sbt
[info] Recompiling project definition...
[info]    Source analysis: 1 new/modified, 0 indirectly invalidated, 0 removed.
[info] Building project hellosbt 0.1 against Scala 2.8.1
[info]    using Project with sbt 0.7.4 and Scala 2.7.7
> idea 
[info] 
[info] == idea ==
[info] Created /scm/gits/codeport/scala/hellosbt/.idea
[info] Created /scm/gits/codeport/scala/hellosbt/project/project.iml
[info] Created /scm/gits/codeport/scala/hellosbt/hellosbt.iml
[info] == idea ==
[success] Successful.
Clone this wiki locally