目的
Scala Sbt でプラグインを使う方法のメモ。Googleで検索しても門外漢用の記事がなくて苦労したため、メモしてみた。
環境
- OS
- Linux www4322gi 3.2.0-64-generic #97-Ubuntu SMP Wed Jun 4 22:04:21 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
- Scala
- version: 2.10.4
事前準備
ScalaとSbtを以下を参考にインストールする。ディレクトリ構成
pwd ----- ~/hello ----- tree . ├── build.properties ├── build.sbt └── src ├── main │   └── scala │   └── com │   └── example │   └── hello │   └── Hello.scala └── test └── scala └── com └── example └── hello └── HelloTest.scala 11 directories, 4 files
Hello.scala
Command
mkdir -p src/main/scala/com/example/hello mkdir -p src/test/scala/com/example/hello
Hello.scala
package com.example.hello import breeze.linalg._ object Hello { def main(args: Array[String]) { val m23 = DenseMatrix( (1.0d, 2.0d, 3.0d), (4.0d, 5.0d, 6.0d)) val plusall = m23 + 0.1d println(m23) println(plusall) } }
HelloTest.scala
package com.example.hello import org.scalatest.FunSuite class HelloTest extends FunSuite { test("Hello should run main") { expectResult()(Hello.main(Array.empty)) } }
ビルド設定
build.properties
sbt.version=0.13.5
build.sbt
name := "hello" version := "1.0" scalaVersion := "2.10.4" libraryDependencies += "org.scalatest" % "scalatest_2.10" % "1.9.1" % "test" libraryDependencies ++= Seq( "org.scalanlp" % "breeze_2.10" % "0.5.2" ) resolvers ++= Seq( "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/releases/" )
ビルド
sbt [info] Set current project to hello (in build file:/home/hidetomo/work/programming-tips/scala-math/hello/) > run [info] Updating {file:/home/hidetomo/work/programming-tips/scala-math/hello/}hello... [info] Resolving org.fusesource.jansi#jansi;1.4 ... [info] downloading http://repo1.maven.org/maven2/org/scalatest/scalatest_2.10/1.9.1/scalatest_2.10-1.9.1.jar ... [info] [SUCCESSFUL ] org.scalatest#scalatest_2.10;1.9.1!scalatest_2.10.jar (6492ms) [info] downloading http://repo1.maven.org/maven2/org/scala-lang/scala-actors/2.10.0/scala-actors-2.10.0.jar ... [info] [SUCCESSFUL ] org.scala-lang#scala-actors;2.10.0!scala-actors.jar (1402ms) [info] Done updating. [info] Compiling 1 Scala source to /home/hidetomo/work/programming-tips/scala-math/hello/target/scala-2.10/classes... [info] Running com.example.hello.Hello Hello! [success] Total time: 20 s, completed Sep 7, 2014 5:00:26 PM > test [info] Compiling 1 Scala source to /home/hidetomo/work/programming-tips/scala-math/hello/target/scala-2.10/test-classes... Hello! [info] HelloTest: [info] - Hello should run main [info] Passed: Total 1, Failed 0, Errors 0, Passed 1 [success] Total time: 6 s, completed Sep 7, 2014 5:01:04 PM [info] Set current project to hello (in build file:/home/hidetomo/work/programming-tips/scala-math/hello/) > run [info] Compiling 1 Scala source to /home/hidetomo/work/programming-tips/scala-math/hello/target/scala-2.10/classes... [info] Running com.example.hello.Hello 1.0 2.0 3.0 4.0 5.0 6.0 1.1 2.1 3.1 4.1 5.1 6.1 [success] Total time: 8 s, completed Sep 7, 2014 5:07:56 PM > test [info] Updating {file:/home/hidetomo/work/programming-tips/scala-math/hello/}hello... [info] Resolving org.fusesource.jansi#jansi;1.4 ... [info] Done updating. [info] Compiling 1 Scala source to /home/hidetomo/work/programming-tips/scala-math/hello/target/scala-2.10/classes... [info] Compiling 1 Scala source to /home/hidetomo/work/programming-tips/scala-math/hello/target/scala-2.10/test-classes... 1.0 2.0 3.0 4.0 5.0 6.0 1.1 2.1 3.1 4.1 5.1 6.1 [info] HelloTest: [info] - Hello should run main [info] Passed: Total 1, Failed 0, Errors 0, Passed 1 [success] Total time: 40 s, completed Sep 7, 2014 6:37:14 PM > exit