simple-build-toolが便利そう

simple-build-toolというツールを簡単に使ってみた。


Google Code Archive - Long-term storage for Google Code Project Hosting.
「Setup」と「Basic Usage」あたりを試してみた。


  • 概要

scalaのビルドツールらしい。
JavaのビルドツールであるMavenscala版という感じ。
プロジェクトに必要なjarの依存関係を解決してくれるのが便利だと思った。
その辺は、Apache Ivyというツールを使っているよう。

  • インストール
# wget http://simple-build-tool.googlecode.com/files/sbt-launch-0.7.4.jar -O /usr/local/bin/sbt-launch-0.7.4.jar
# ln -s /usr/local/bin/sbt-launch-0.7.4.jar /usr/local/bin/sbt-launch.jar
# cat << _EOD_ > /usr/local/bin/sbt
#!/bin/sh
java -Xmx512M -jar `dirname $0`/sbt-launch.jar "$@"
_EOD_
# chmod u+x /usr/local/bin/sbt
  • 使い方
# sbt help
[info] Building project test 1.0 against Scala 2.7.7
[info]    using sbt.DefaultProject with sbt 0.7.4 and Scala 2.7.7
You may execute any project action or method or one of the commands described below.
Available Commands:
   <action name> : Executes the project specified action.
   <method name> <parameter>* : Executes the project specified method.
   <processor label> <arguments> : Runs the specified processor.
   ~ <command> : Executes the project specified action or method whenever source files change.
   < file : Executes the commands in the given file.  Each command should be on its own line.  Empty lines and lines beginning with '#' are ignored
   + <command> : Executes the project specified action or method for all versions of Scala defined in crossScalaVersions.
   ++<version> <command> : Changes the version of Scala building the project and executes the provided command.  <command> is optional.
   * : Prefix for commands for managing processors.  Run '*help' for details.
   ! : Prefix for history commands.  Run '!' for history command help.
   actions : Shows all available actions.
   reload : Reloads sbt, picking up modifications to sbt.version or scala.version and recompiling modified project definitions.
   help : Displays this help message.
   current : Shows the current project, Scala version, and logging level.
   debug, info, warn, error : Set logging for the current project to the specified level.
   trace 'on', 'nosbt', 'off', or <integer> : Configures stack trace logging. 'nosbt' prints stack traces up to the first sbt frame.  An integer gives the number of frames to show per exception.
   project <project name> : Sets the currently active project.
   projects : Shows all available projects.
   exit, quit : Terminates the build.
   set <property> <value> : Sets the value of the property given as its argument.
   get <property> : Gets the value of the property given as its argument.
   console-project : Enters the Scala interpreter with the current project definition bound to the variable 'current' and all members imported.
   builder : Set the current project to be the project definition builder.
   shell : Enters the sbt interactive shell
[info] 
[info] Total session time: 1 s, completed 2010/09/05 0:54:39
[success] Build completed successfully.

# sbt actions
[info] Building project test 1.0 against Scala 2.7.7
[info]    using sbt.DefaultProject with sbt 0.7.4 and Scala 2.7.7
        -empty
        clean: Deletes all generated files (the target directory).
        clean-cache: Deletes the cache of artifacts downloaded for automatically managed dependencies.
        clean-lib: Deletes the managed library directory.
        clean-plugins
        compile: Compiles main sources.
        console: Starts the Scala interpreter with the project classes on the classpath.
        console-quick: Starts the Scala interpreter with the project classes on the classpath without running compile first.
        copy-resources: Copies resources to the target directory where they can be included on classpaths.
        copy-test-resources: Copies test resources to the target directory where they can be included on the test classpath.
        deliver
        deliver-local
        doc: Generates API documentation for main Scala source files using scaladoc.
        doc-all: Generates both main and test documentation.
        doc-test: Generates API documentation for test Scala source files using scaladoc.
        exec
        graph-pkg
        graph-src
        increment-version: Increments the micro part of the version (the third number) by one. (This is only valid for versions of the form #.#.#-*)
        javap
        make-pom
        package: Creates a jar file containing main classes and resources.
        package-all: Executes all package tasks except package-project.
        package-docs: Creates a jar file containing generated API documentation.
        package-project: Creates a zip file containing the entire project, excluding generated files.
        package-src: Creates a jar file containing all main source files and resources.
        package-test: Creates a jar file containing test classes and resources.
        package-test-src: Creates a jar file containing all test source files and resources.
        publish
        publish-local
        release: Compiles, tests, generates documentation, packages, and increments the version.
        run: Runs the main class for the project with the provided arguments.
        sh
        test: Runs all tests detected during compilation.
        test-compile: Compiles test sources.
        test-failed: Runs the tests provided as arguments if they have not succeeded.
        test-javap
        test-only: Runs the tests provided as arguments.
        test-quick: Runs the tests provided as arguments if they have not succeeded or their dependencies changed.
        test-run: Runs a test class with a main method with the provided arguments.
        update: Resolves and retrieves automatically managed dependencies.
  • プロジェクト作成
# mkdir hw
# echo 'object Hi { def main(args: Array[String]) { println("Hi!") } }' > hw.scala
# sbt
Project does not exist, create new project? (y/N/s) s
Getting Scala 2.7.7 ...
:: retrieving :: org.scala-tools.sbt#boot-scala
        confs: [default]
        2 artifacts copied, 0 already retrieved (9911kB/77ms)
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/63ms)
[success] Successfully initialized directory structure.
[info] Building project test 1.0 against Scala 2.7.7
[info]    using sbt.DefaultProject with sbt 0.7.4 and Scala 2.7.7
> run
[info]
[info] == compile ==
[info]   Source analysis: 1 new/modified, 0 indirectly invalidated, 0 removed.
[info] Compiling main sources...
[info] Compilation successful.
[info]   Post-analysis: 2 classes.
[info] == compile ==
[info]
[info] == copy-resources ==
[info] == copy-resources ==
[info]
[info] == run ==
[info] Running Hi
Hi!
[info] == run ==
[success] Successful.
[info]
[info] Total time: 5 s, completed 2010/09/05 0:19:16
> quit
[info]
[info] Total session time: 135 s, completed 2010/09/05 0:21:12
[success] Build completed successfully.
  • 外部ライブラリのインストール

外部ライブラリはリポジトリに登録されている必要がある。
http://scala-tools.org/repo-releases/

# mkdir project/build
# cat << _EOD_ > project/build/HelloWoldProject.scala
import sbt._

class HelloWorldProject(info: ProjectInfo) extends DefaultProject(info)
{
  val scalatools_release = "Scala Tools Snapshot" at
  "http://scala-tools.org/repo-releases/"

  val liftVersion = "2.0"

  override def libraryDependencies = Set(
    "net.liftweb" % "lift-mapper" % liftVersion % "compile->default",
    "net.liftweb" % "lift-wizard" % liftVersion % "compile->default",
    "org.mortbay.jetty" % "jetty" % "6.1.22" % "test->default",
    "junit" % "junit" % "4.5" % "test->default",
    "org.scala-tools.testing" % "specs" % "1.6.2.1" % "test->default",
    "com.h2database" % "h2" % "1.2.121"
  ) ++ super.libraryDependencies
}
_EOD_
# sbt update
[info] Building project test 1.0 against Scala 2.7.7
[info]    using HelloWorldProject with sbt 0.7.4 and Scala 2.7.7
[info] 
[info] == update ==
[info] :: retrieving :: test#test_2.7.7 [sync]
[info]  confs: [compile, runtime, test, provided, system, optional, sources, javadoc]
[info]  2 artifacts copied, 24 already retrieved (1218kB/79ms)
[info] == update ==
[success] Successful.
[info] 
[info] Total time: 33 s, completed 2010/09/05 2:39:24
[info] 
[info] Total session time: 34 s, completed 2010/09/05 2:39:24
[success] Build completed successfully.

# find lib_managed
lib_managed
lib_managed/scala_2.7.7
lib_managed/scala_2.7.7/test
lib_managed/scala_2.7.7/test/junit-4.5.jar
lib_managed/scala_2.7.7/test/servlet-api-2.5-20081211.jar
lib_managed/scala_2.7.7/test/jetty-util-6.1.22.jar
lib_managed/scala_2.7.7/test/jetty-6.1.22.jar
lib_managed/scala_2.7.7/test/specs-1.6.2.1.jar
lib_managed/scala_2.7.7/compile
lib_managed/scala_2.7.7/compile/h2-1.2.134.jar
lib_managed/scala_2.7.7/compile/lift-webkit-2.0.jar
lib_managed/scala_2.7.7/compile/lift-wizard-2.0.jar
lib_managed/scala_2.7.7/compile/slf4j-api-1.5.11.jar
lib_managed/scala_2.7.7/compile/commons-codec-1.3.jar
lib_managed/scala_2.7.7/compile/paranamer-2.0.jar
lib_managed/scala_2.7.7/compile/lift-common-2.0.jar
lib_managed/scala_2.7.7/compile/lift-actor-2.0.jar
lib_managed/scala_2.7.7/compile/lift-testkit-2.0.jar
lib_managed/scala_2.7.7/compile/activation-1.1.jar
lib_managed/scala_2.7.7/compile/lift-json-2.0.jar
lib_managed/scala_2.7.7/compile/lift-util-2.0.jar
lib_managed/scala_2.7.7/compile/log4j-1.2.14.jar
lib_managed/scala_2.7.7/compile/slf4j-log4j12-1.5.11.jar
lib_managed/scala_2.7.7/compile/mail-1.4.1.jar
lib_managed/scala_2.7.7/compile/lift-mapper-2.0.jar
lib_managed/scala_2.7.7/compile/joda-time-1.6.jar
lib_managed/scala_2.7.7/compile/commons-httpclient-3.1.jar
lib_managed/scala_2.7.7/compile/commons-fileupload-1.2.1.jar
lib_managed/scala_2.7.7/compile/derby-10.5.3.0_1.jar
lib_managed/scala_2.7.7/compile/commons-logging-1.0.4.jar
  • 参考

Google Code Archive - Long-term storage for Google Code Project Hosting.
Lift :: Home