Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude jar in final sbt assembly plugin

I need to exclude spark and test dependencies from my final assembly jar. I tried to use provider but it was not working.

libraryDependencies ++= Seq("org.apache.spark" % "spark-core_2.11" % "2.0.1" % "provided")

and execute sbt assembly.

Please help me resolve this issue.

like image 883
John Avatar asked Jan 27 '17 12:01

John


People also ask

How to exclude dependencies in SBT?

We exclude dependencies in SBT by using either the exclude or excludeAll keywords. It's important to understand which one to use: excludeAll is more flexible but cannot be represented in a pom. xml. Therefore, we should use exclude if a pom.

What does SBT Assembly do?

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. Sometimes, we may not want certain libraries to be part of our JAR file.


1 Answers

Use exclude option of assembly plugin filtering by direct name or with contains

assemblyExcludedJars in assembly := {
    val cp = (fullClasspath in assembly).value
    cp filter { f =>
      f.data.getName.contains("spark-core") ||
      f.data.getName == "spark-core_2.11-2.0.1.jar"
    }
  }
like image 142
FaigB Avatar answered Nov 15 '22 21:11

FaigB