LoginSignup
11
8

More than 5 years have passed since last update.

sbt runでprovidedな依存ライブラリをクラスパスに含める

Posted at

本番環境ではライブラリがインストールされているからそれを使いたいけど、ローカルで実行/テストするときは環境作るの面倒だからsbt管理のライブラリを使いたいよってケースです。

build.sbtで以下のように設定するとsbt runおよびsbt run-mainでprovidedにしたライブラリもクラスパスに含めて実行されます。

libraryDependencies ++= Seq(
  "org.apache.spark" %% "spark-core" % "1.3.1" % "provided",
  "org.apache.spark" %% "spark-mllib"  % "1.3.1" % "provided",
  "com.github.scopt" %% "scopt" % "3.3.0"
)

run in Compile <<= Defaults.runTask(fullClasspath in Compile, mainClass in (Compile, run), runner in (Compile, run))
runMain in Compile <<= Defaults.runMainTask(fullClasspath in Compile, runner in (Compile, run))

参考

以下の記事だとsbt run-mainのときにクラスパスに含まれないので、それだけ補足しました。

11
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
8