Scala code build with sbt assembly , failing - scala

I am using sbt 0.13.7 and Scala 2.11.4 on a Windows machine to compile my code into a fat jar, that I eventually want to run on a Linux machine.
Below is my build.sbt file:
import AssemblyKeys._
name := "Simple Project"
version := "1.0"
organization := "com.myorg"
scalaVersion := "2.11.4"
libraryDependencies ++= Seq(
// Spark dependency
"org.apache.spark" % "spark-core_2.10" % "1.2.0" % "provided",
// Third party libraries
"net.sf.jopt-simple" % "jopt-simple" % "4.3",
"joda-time" % "joda-time" % "2.0"
)
libraryDependencies += Defaults.sbtPluginExtra("com.eed3si9n" % "sbt-assembly" % "0.7.2", "0.11.2", "2.9.1")
// This statement includes the assembly plugin capabilities
assemblySettings
// Configure jar named used with the assembly plug-in
jarName in assembly := "my-project-assembly.jar"
// A special option to exclude Scala itself form our assembly jar, since Spark
// already bundles Scala.
assemblyOption in assembly := (assemblyOption in assembly).value.copy(includeScala = false)
The error I am facing is:
build.sbt:16: error: type mismatch;
found : Seq[sbt.Project.Setting[_]]
required: sbt.internals.DslEntry
assemblySettings
^
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?

Are you using sbt-assembly 0.12.0? If so, you don't need assemblySettings any more since it's an auto plugin.
Edit:
You have to include
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.12.0")
in project/*.sbt like project/assembly.sbt, not build.sbt.

Related

log4j2 in scala on sbt complie gives Unresolved dependencies path

I'm trying to use log4j2 in scala.
Below is my build.sbt
name := "trial"
version := "0.1"
scalaVersion := "2.13.1"
libraryDependencies += "org.apache.logging.log4j" %% "log4j-api" % "2.12.1"
libraryDependencies += "org.apache.logging.log4j" %% "log4j-core" % "2.12.1"
libraryDependencies += "org.apache.logging.log4j" %% "log4j-api-scala" % "2.12.1"
How to resolve these errors:
[warn] Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading org.apache.logging.log4j:log4j-api_2.13:2.12.1
sbt.librarymanagement.ResolveException: Error downloading org.apache.logging.log4j:log4j-api_2.13:2.12.1
not found: /Users/username/.ivy2/local/org.apache.logging.log4j/log4j-api_2.13/2.12.1/ivys/ivy.xml
Note :
There is no directory /Users/username/.ivy2/local/
but I can see there is /Users/username/.ivy2/cache/
and plugins log4j-api,core,api-scala are present in cache.
The IDE i'm using is IntelliJ IDEA.
There are multiple problems
You are using Scala 2.13 however the latest build of log4j-api-scala is for Scala 2.12.
The latest version of log4j-api-scala is 11.0 not 2.12.1
log4j-api and log4j-core are Java libraries so we should use single % instead of double%%

get No Class Def Found Error:scala/Product$class when packaging fat jar

Created a simple helloworld scala program on intellij and tried to add assembly plug in. But every time I run "assembly" on sbt console I get no class def. found error.
Build.sbt:
name := "testsbt"
version := "1.2.1"
scalaVersion := "2.12.6"
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.1" %"test"
autoScalaLibrary := true
Assembly.sbt:
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.7")
Error message:
[IJ]sbt:testsbt> assembly
[error] java.lang.NoClassDefFoundError: scala/Product$class
scala version and sbt version are matched.
Thanks for the help!

Scala SBT Cannot Add Dependency (geotrellis)

I'm new to Scala and working with IntelliJ Community Edition.
I open a new project and edit the build.sbt file to contain the following:
name := "test"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
"org.locationtech.geotrellis" %% "geotrellis-raster" % "1.0.0" % "1.1.0" ,
"org.locationtech.geotrellis" % "geotrellis-shapefile_2.11" % "1.1.0"
).map(_
.exclude("com.azavea.geotrellis", "geotrellis-proj4_2.11")
.exclude("com.azavea.geotrellis", "geotrellis-raster_2.11")
)
After that, I refresh the project, and I get the following errors in the error file:
[error] (*:ssExtractDependencies) java.lang.IllegalArgumentException: Cannot add dependency 'org.locationtech.geotrellis#geotrellis-raster_2.11;1.0.0' to configuration '1.1.0' of module default#test_2.11;1.0 because this configuration doesn't exist!
[error] (*:update) java.lang.IllegalArgumentException: Cannot add dependency 'org.locationtech.geotrellis#geotrellis-raster_2.11;1.0.0' to configuration '1.1.0' of module default#test_2.11;1.0 because this configuration doesn't exist!
What am I doing wrong here?
Main issue seems to be two different version numbers on one of your dependencies.
"org.locationtech.geotrellis" %% "geotrellis-raster" % "1.0.0" % "1.1.0"
Should be
"org.locationtech.geotrellis" %% "geotrellis-raster" % "1.0.0"
or
"org.locationtech.geotrellis" %% "geotrellis-raster" % "1.1.0"
if you want the 1.1.0 version

How can I ignore scala library while sbt assembly

I am using sbt to build my scala project.
This is my build.sbt:
name := "My Spark App"
version := "1.0"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.2.0" % "provided"
libraryDependencies += "org.apache.spark" %% "spark-sql" % "1.2.0" % "provided"
I am running sbt assembly to create an assembly jar, but I found a scala directory containing scala library class codes.
Is it possible to take scala library as a provided dependency, since the run-time environment already contains scala?
From docs, this might help
assemblyOption in assembly := (assemblyOption in assembly).value.copy(includeScala = false)

How to add jdbc dependency to Play project?

I'm using play 2.2.2.
I'd like to enable jdbc library in a Play/Scala project as mentioned in Accessing an SQL database.
Here's my rootproject/project/plugins.sbt:
libraryDependencies ++= Seq(
jdbc
"com.google.zxing" % "core" % "2.0",
"mysql" % "mysql-connector-java" % "5.1.27",
"com.typesafe.slick" %% "slick" % "2.1.0",
"org.slf4j" % "slf4j-nop" % "1.6.4"
)
While compiling the project, I get following jdbc not found error,
$ /usr/local/play-2.2.2/play compile
/packup/smartad-core/project/plugins.sbt:8: error: not found: value jdbc
jdbc
^
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q
My rootproject/build.sbt simply is
import play.Project._
name := "smartad-backend"
version := "1.0"
playScalaSettings
References
https://www.playframework.com/documentation/2.3.x/ScalaAnorm
You should combine both of those blocks into your build.sbt file. plugins.sbt is for adding sbt plugins, such as the play sbt plugin. But that's about it.
import play.Project._
name := "smartad-backend"
version := "1.0"
playScalaSettings
libraryDependencies ++= Seq(
jdbc,
...
)