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
.
The sbt-assembly plugin is an SBT plugin for building a single independent fat JAR file with all dependencies included. This is inspired by the popular Maven assembly plugin, which is used to build fat JARs in Maven.
A plugin can define a sequence of sbt settings that are automatically added to all projects or that are explicitly declared for selected projects. For example, a plugin might add a proguard task and associated (overridable) settings. Finally, a plugin can define new commands (via the commands setting).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With