9

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

So far these are the steps I've taken.

I created a plugins.sbt file:

$ 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:

$ 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/build.sbt:1: error: not found: value AssemblyKeys
import AssemblyKeys._ 
Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319
dsg
  • 12,924
  • 21
  • 67
  • 111
  • Do you get an error message that the plugin can not be downloaded? – Christian Dec 12 '11 at 09:32
  • @Christian -- No, actually, I don't get a message like that. I believe that the plugin is being downloaded. – dsg Dec 12 '11 at 10:05
  • It works here, exactly with the statements you have above (I have the plugin still in `project/plugins/build.sbt` which is now deprecated, but I doubt that this makes a difference). What happens if you do `sbt reload clean update`, does it download the plugin? – 0__ Dec 12 '11 at 11:09

3 Answers3

12
  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")
    
user272735
  • 10,473
  • 9
  • 65
  • 96
dsg
  • 12,924
  • 21
  • 67
  • 111
  • Sorry for newbie question, what if my project does not use build.sbt but uses special class derived from Build (I believe its sbt.Build). I want to convert it to fat-jar and I need to add the following options which I see in sample project - seq(webSettings :_*) and assemblySettings. The project is here - https://github.com/zcox/lift-jetty-fatjar – kirhgoff Jul 01 '13 at 15:56
3

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

jrudolph
  • 8,307
  • 4
  • 32
  • 50
1

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

So you simply should do

seq(assemblySettings: _*)

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

Vasil Remeniuk
  • 20,519
  • 6
  • 71
  • 81