SBT Assembly not working (not a valid command)
Asked Answered
P

2

8

I have tried a lot of solutions that I could find related to this topic. Above all of them,

sbt assembly command not found

looked the most related, but that did not solve it.

I am using sbt 13.7

build.sbt:

lazy val commonSettings = Seq(
  organization := "com.example",
  version := "0.1.0"
)

lazy val app = (project in file(".")).
  settings(commonSettings: _*).
  settings(
    name := "fat-jar-test"
  )

assembly.sbt:

resolvers += Resolver.url("bintray-sbt-plugins", url("http://dl.bintray.com/sbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns)

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")

project structure

root
  |
  src
  target
  project
    |
    build.sbt
    assembly.sbt

In sbt I compile succesfully, I can package succesfully, but when I run assembly command I get:

[error] Not a valid command: assembly
[error] Not a valid project ID: assembly
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: assembly
[error] assembly
[error]

I am using Intellij but running sbt from terminal.
I am on Mac OSX.
I originally downloaded sbt and installed from their site, normal installation. I removed and tried installing from macports, no difference.
I had scala version in build.sbt setting, but removed it because I was getting errors and read the 2.11.x does not work with sbt. That stopped errors, but I still have assembly problem.

EDIT:

I was unsure of placement of build.sbt in this structure. Before I had it in the root directory. At suggest of Roman below, I have moved it back to there, but alas I receive the exact same error.

Pumpkin answered 23/3, 2016 at 18:39 Comment(2)
What plugins command shows?Cashew
sbt.plugins.IvyPlugin: enabled in app sbt.plugins.JvmPlugin: enabled in app sbt.plugins.CorePlugin: enabled in app sbt.plugins.JUnitXmlReportPlugin: enabled in appPumpkin
C
16

Pull 1 level up your build.sbt. It should reside in project root, not it project.

Also it's possible to have build.sbt in project folder as well, it means a different thing. Read Organizing Build document for some insight.

UPD: as @marios has suggested, can you also put resolvers to your build.sbt. Also, it's important to set SNAPSHOT version for your build. The whole content of your build.sbt should be the following:

scalaVersion in ThisBuild := "2.11.7"

lazy val commonSettings = Seq(
  organization := "com.example",
  version := "0.1.0-SNAPSHOT"
)

lazy val app = (project in file(".")).
  settings(commonSettings: _*).
  settings(
    name := "fat-jar-test"
  ).
  enablePlugins(AssemblyPlugin)

resolvers in Global ++= Seq(
  "Sbt plugins"                   at "https://dl.bintray.com/sbt/sbt-plugin-releases",
  "Maven Central Server"          at "http://repo1.maven.org/maven2",
  "TypeSafe Repository Releases"  at "http://repo.typesafe.com/typesafe/releases/",
  "TypeSafe Repository Snapshots" at "http://repo.typesafe.com/typesafe/snapshots/"
)

Then, add two more files to root/project folder:

root/project/build.properties contains a single line:

sbt.version=0.13.7

root/project/plugins.sbt also contains a single line:

addSbtPlugin("com.eed3si9n"       %  "sbt-assembly"            % "0.12.0")

Now, remove your root/project/assembly.sbt file (although it's fine to have it instead of plugins.sbt, but let's just try - this configuration always works for me).

Now, your project layout should be the following:

root
  |
  build.sbt
  src
  project
    |
    plugins.sbt
    build.properties

Reload sbt and try plugins command. You should see sbtassembly.AssemblyPlugin there.

Cashew answered 23/3, 2016 at 18:45 Comment(8)
I had tried this, and just changed it back to this. Exact same error. I will edit question to reflect this.Pumpkin
This answer is very close to correct so I don't want to add a new address. Your build.sbt files needs to be inside your root directory. Also the resolvers statements should be inside your build.sbt and not inside the plugin sbt file.Canaliculus
@Canaliculus I had tried that also, and at your suggestion I put it back in build.sbt. So far no possible combination has worked and I get same error. Roman asked for plugins output in comments under main question. From that it looks like the plugin is not listed.Pumpkin
You need to add enablePlugins(AssemblyPlugin)Loppy
This was helpful. For me, the missing item was the root/project/plugins.sbt file. Thanks for the help!Thistledown
@DexterLegaspi where do I need to add enablePlugins(AssemblyPlugin)? At plugins.sbt?Slovenia
I had tried this but I got this error error: not found: value AssemblyPlugin enablePlugins(AssemblyPlugin) can you help me please ?Wildlife
getting the same error as above ^ has anyone solved this?Clammy
C
5

The same problem occurred for me. i had the correct structure of files and folder.

The mistake i was doing is running the sbt assembly from the myproject/project folder. Try running same command from top project folder. run from C:\Users*\IdeaProjects\untitled9 not from C:\Users*\IdeaProjects\untitled9\project

Cyclades answered 28/8, 2020 at 5:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.