Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT Assembly not working (not a valid command)

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.

like image 795
lbollar Avatar asked Mar 23 '16 18:03

lbollar


Video Answer


2 Answers

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.

like image 126
Roman Avatar answered Oct 08 '22 23:10

Roman


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

like image 43
Praveen Patel Avatar answered Oct 09 '22 00:10

Praveen Patel