8

Posting this only because no other suggested solutions helped. I have a very simple one-class Scala sbt project which needs to be a runnable .jar file. It has some java dependencies so sbt package won't work for me, I need a fat jar. The project has the following structure.

├── build.sbt
├── project
│   ├── assembly.sbt
│   ├── build.properties
│   ├── project
│   └── target
├── README.md
├── src
│   ├── main
│   └── test
├── target
│   ├── scala-2.12
│   ├── specs2-reports
│   ├── streams
│   └── test-reports

It has one main class and one test spec. In order to make sbt generate a fat jar I added assembly.sbt into project dir and modified my build.sbt accordingly.

import AssemblyKeys._

name := "myproj"

version := "1.0"

scalaVersion := "2.12.8"

libraryDependencies ++= Seq(
  "au.com.bytecode" %% "opencsv" % "2.4",
  "org.specs2" %% "specs2-core" % "4.3.0" % "test"
)

scalacOptions in Test ++= Seq("-Yrangepos")

assemblyMergeStrategy in assembly := {
  case PathList("META-INF", xs @ _*) => MergeStrategy.discard
  case x => MergeStrategy.first
}

However,import AssemblyKeys._ is red with cannot resolve symbol? Trying it from console gives me

import AssemblyKeys._
       ^
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? 

What else have I forgotten because assebly github page does not state that we need to do anything else. My sbt version is sbt 1:1.2.8-1.

1 Answer 1

12

Under your project directory, you need to add a plugins.sbt file which has the following included:

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

Then, delete AssemblyKeys._ and refresh sbt. Only after a successful refresh you'll be able to insert that import

3
  • 2
    Once I did this and tried to run compile in sbt console I got unresolved opencsv dependency exception. I then closed idea completely and also removed ~/.sbt/0.13 dir and tried again. sbt assembly successfully worked! Commented Feb 21, 2019 at 13:33
  • @minerals Yeah sometimes caching goes bananas, although if you're on sbt 1.2.8, everything should be under the ~/.sbt/1.0 directory if I recall correctly. Commented Feb 21, 2019 at 13:35
  • It should. But I also had 0.13 there for some reason and thought that it might conflict with 1.0. Regarding Idea IDE, I think it does not work well with sbt at all :( Commented Feb 21, 2019 at 13:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.