简体   繁体   English

什么时候使用“ sbt汇编”和“ sbt编译&& sbt软件包”?

[英]When to use “sbt assembly” and “sbt compile && sbt package”?

I would like to know when should I use sbt assembly and when sbt compile && sbt package ? 我想知道什么时候应该使用sbt assembly ,什么时候使用sbt compile && sbt package

I'm coding a program in my local computer using Intellij IDEA and I'm compiling it with sbt compile && sbt package , then I'm going to upload it to a cluster and run it using spark-submit . 我正在使用Intellij IDEA在本地计算机上编码一个程序,并使用sbt compile && sbt package ,然后将其上传到集群并使用spark-submit运行它。 Is this the best way? 这是最好的方法吗? When should I use sbt assembly ? 我什么时候应该使用sbt assembly

I would like to know when should I use sbt assembly and when sbt compile && sbt package ? 我想知道什么时候应该使用sbt assembly ,什么时候使用sbt compile && sbt package

Quoting sbt-assembly 's website (which gives sbt assembly ): 引用sbt-assembly的网站(提供sbt assembly ):

The goal is simple: Create a fat JAR of your project with all of its dependencies. 目标很简单:使用所有依赖项为项目创建一个胖JAR。

Any dependency in build.sbt (that is not marked as Provided ) is going to be part of the final jar file that is called an uber-jar. build.sbt任何依赖build.sbt (未标记为Provided )都将成为称为uber-jar的最终jar文件的一部分。

There are at least two reasons why you'd like to use the plugin: 您要使用该插件的原因至少有两个:

  1. Have all dependencies bundled together in one jar file that is much easier to deploy to production (akin to a Docker image) 将所有依赖项捆绑在一个jar文件中,这样更易​​于部署到生产环境(类似于Docker映像)
  2. Run your application with one Spark version, say 2.0.0, with a cluster that has spark-submit from Spark 1.6.0 使用具有Spark 1.6.0的Spark spark-submit的集群,以一个Spark版本(例如2.0.0)运行您的应用程序

You use sbt compile && sbt package to compile and package the classes of your application (which by the way does not have to use Spark whatsoever). 您可以使用sbt compile && sbt package来编译和打包应用程序的类(顺便说一句,它不必使用Spark)。 That jar file does not include the dependencies of your application so any dependencies have to be provided in some other way (and makes deployment a bit tricker). 该jar文件不包括应用程序的依赖项,因此必须以其他方式提供任何依赖项(并使部署有些麻烦)。

NB: sbt compile && sbt package is just a longer variant of sbt compile package which given that compile task is a dependency of package is just sbt package . 注意: sbt compile && sbt package只是sbt compile package一个较长的变体,考虑到compile任务是该package的依赖项,因此它只是sbt package

"sbt assembly" is good to use when you want to have uber jar with all dependency included. 当您想要包含所有依赖项的uber jar时,“ sbt程序集”很好用。 You will need assembly plugin to use "sbt assembly". 您将需要程序集插件才能使用“ sbt程序集”。

Generally, This kind of jar is good to build when you don't want to provide dependent jars separately on target machine. 通常,当您不想在目标计算机上单独提供依赖的jar时,这种jar可以很好地构建。 You can avoid dependent 3rd party jar version mismatch related issues by this kind of packaging. 通过这种包装,可以避免与第三方3d jar版本相关的不匹配相关问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM