Tell SBT to collect all my dependencies together

杀马特。学长 韩版系。学妹 提交于 2019-12-20 18:26:08

问题


When building a web application SBT is able to collect all my jar dependencies into the WAR file.

Is this possible to have SBT put all the jars I depend on in my non-web application into a directory so I can easily put them onto my class path when running the app?


回答1:


Yes, you can put something like this in your project definition class:

val libraryJarPath = outputPath / "lib"

def collectJarsTask = {
  val jars = mainDependencies.libraries +++ mainDependencies.scalaJars
  FileUtilities.copyFlat(jars.get, libraryJarPath, log)
}

lazy val collectJars = task { collectJarsTask; None } dependsOn(compile)

and run the task via collect-jars in your SBT console. This will copy the scala-library.jar and the jars used for compilation in a directory called lib in the same directory as your classes directory.




回答2:


You can use sbt-assembly to make a fat jar with all dependencies: https://github.com/sbt/sbt-assembly




回答3:


In my honest opinion don't bother with sbt-assembly. I'm new with scala but I'm quite technology agnostic, I handle a lot of technologies and sbt-assembly it's not clean. Just an opinion.

I would recommend you sbt-pack. Awesome piece of work. It will give you the runnable scripts as well, for both.. WINDOWS AND LINUX.

https://github.com/xerial/sbt-pack



来源:https://stackoverflow.com/questions/5564690/tell-sbt-to-collect-all-my-dependencies-together

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!