scala 使用 sbt 0.11.2 安装 sbt-assembly

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8470889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 03:44:27  来源:igfitidea点击:

installing sbt-assembly with sbt 0.11.2

scalajarsbtsbt-assembly

提问by dsg

I am trying to install sbt-assembly by following the instructionsin order to make a stand-alone jar that can run on a computer without scala installed.

我正在尝试按照说明安装 sbt-assembly,以便制作一个可以在没有安装 scala 的计算机上运行的独立 jar。

So far these are the steps I've taken.

到目前为止,这些是我采取的步骤。

I created a plugins.sbt file:

我创建了一个 plugins.sbt 文件:

$ cat sbt/project/plugins.sbt 
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.7.2")

And I added the following to the beginning of my build.sbt file:

我在 build.sbt 文件的开头添加了以下内容:

$ head -n3 sbt/build.sbt 
import AssemblyKeys._ // put this at the top of the file

seq(assemblySettings: _*)

But when I run sbt, I get the following error:

但是当我运行 sbt 时,出现以下错误:

sbt/build.sbt:1: error: not found: value AssemblyKeys
import AssemblyKeys._ 

回答by dsg

  1. Make sure you are running sbt version at least 0.11 by typing

    $ sbt sbt-version

    at the bash prompt.

  2. Make sure you have the plugins file set up as follows:

    $ cat sbt/project/plugins.sbt
    
    addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.7.2")
    
  3. Make your build file (build.sbt) look like this:

    import AssemblyKeys._ 
    
    seq(assemblySettings: _*)
    
    name := "my_project"
    
    version := "1.0"
    
    scalaVersion := "2.9.1"
    
    libraryDependencies ++= Seq(
      "org.scalatest" %% "scalatest" % "1.6.1" % "test",
      "commons-lang" % "commons-lang" % "2.6"
    )
    
    traceLevel in run := 0
    
    fork in run := true
    
    scalacOptions ++= Seq("-optimize")
    
    // The following is the class that will run when the jar is compiled!
    
    mainClass in assembly := Some("MyMain")
    
  1. 通过键入确保您运行的 sbt 版本至少为 0.11

    $ sbt sbt-version

    在 bash 提示符下。

  2. 确保您的插件文件设置如下:

    $ cat sbt/project/plugins.sbt
    
    addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.7.2")
    
  3. 使您的构建文件 ( build.sbt) 看起来像这样:

    import AssemblyKeys._ 
    
    seq(assemblySettings: _*)
    
    name := "my_project"
    
    version := "1.0"
    
    scalaVersion := "2.9.1"
    
    libraryDependencies ++= Seq(
      "org.scalatest" %% "scalatest" % "1.6.1" % "test",
      "commons-lang" % "commons-lang" % "2.6"
    )
    
    traceLevel in run := 0
    
    fork in run := true
    
    scalacOptions ++= Seq("-optimize")
    
    // The following is the class that will run when the jar is compiled!
    
    mainClass in assembly := Some("MyMain")
    

回答by jrudolph

Make sure you don't have a project/plugins folder lying around. This may prevent other mechanisms of specifying plugins from working.

确保您周围没有项目/插件文件夹。这可能会阻止其他指定插件的机制工作。

回答by Vasil Remeniuk

You shouldn't import plugin settings into build.sbt(basic configuration): 1) build.sbtis not a normal Scala source file 2) plugin settings are pre-imported.

您不应该将插件设置导入build.sbt基本配置):1)build.sbt不是普通的 Scala 源文件 2) 插件设置是预先导入的。

So you simply should do

所以你应该做

seq(assemblySettings: _*)

Imports are required only when you use full/extended build configuration.

仅当您使用完整/扩展构建配置时才需要导入。